Custom autoroute to slug

Topics: Customizing Orchard, Writing modules
Aug 8, 2012 at 6:00 AM

hi,

i have a custom  autoroute

{Content.Id}/{Content.Fields.TrackPart.Category}/{Content.Fields.TrackPart.Artist}/{Content.Slug}

WHICH GIVES OUT PUT AS BELOW

localhost:30320/33/DanceHall/Katy%20Perry/youve-lost-that-lovin  

 

BUT I WANTALL SMALL LETTERS AND WITH hyphen LIKE SLUG

localhost:30320/33/dance-hall/katy-perry/youve-lost-that-lovin 

 

PLEASE HELP

 

 

 

Thanks

shiva

Developer
Aug 8, 2012 at 5:21 PM
Edited Aug 8, 2012 at 5:21 PM

In IIS 7, there's a rewrite rule out of the box which you could enable.

As for replacing spaces with hyphens, I'm not sure. Perhaps the ReplaceOptions used in Tokenizer.Replace should be extended with a "space to dash" option.

Coordinator
Aug 8, 2012 at 5:36 PM

I think the best option is to expose the SLug behavior into a Text token, like the "Limit" token. You can do it in your own code right now, and open an issue for that. Totally makes sense to me.

Developer
Aug 8, 2012 at 6:31 PM

Nice, yes.

Aug 9, 2012 at 1:37 PM

hi,

Can you explain a little more please .  I am new to orchard , jsut starting to create my own module

or can you point me to some urls you know

Thank you very much

thanks

shiva

Developer
Aug 9, 2012 at 6:50 PM

Have a look at the TextTokens class in the Orchard.Tokens module. What you could do is copy that class to your own module, strip the implementation except for one token, e.g. "HtmlEncode" and replace that name + implementation with your own logic to replace spaces with dashes.

Dec 7, 2012 at 4:01 PM

So is the only way to do this by creating your own module? I was just trying to create my own content type and was using this:

{Content.Fields.EventCalendar.EventName.Slug}

When I do that, I get "" back.

If I do it without the .Slug I get the name with spaces.

Developer
Dec 8, 2012 at 6:03 PM

Which makes sense if EventName doesn't resolve to a content item. So I do think you will have to write your own module and take Sebastien's advice by exposing the Slug behavior into a Text token, so that the Slug behavior can be applied to any text string, not just to the DisplayText of a content item. If you want you could also open an issue for it so we can consider it to include it in the Tokens module. To implement it yourself, simply follow the TextTokens and SlugTokens classes as an example, as they contain all the code you need.

Dec 17, 2012 at 8:57 PM

Actually I figured it out. What it needs to be is:

{Content.Fields.EventCalendar.EventName.Text.Slug}

Thanks for the reply.