ASPX templates
Version 5.x > ASPX templates > Choose template according to URL View modes: 
User avatar
Member
Member
ricardo.fiel - 2/9/2010 6:48:04 AM
   
Choose template according to URL
Hi all,

How can I choose a template for a given doc. type based on the current url? Here's an example:

Assuming I have the following doctypes:
- NewsItem
- NewsFolder (has NewsItems as children)
- Platform (Eg: PS3, Wii, XBOX,... - has NewsFolder as child)
- Game (Eg: Halo, Sonic, etc.. - has NewsFolder as child)

As a NewsFolder can be under Platform or Game, I need to show a different template for each parent doctype. Choosing the template in CMSDesk is not an option, as a NewsItem under Game/NewsFolder can be moved to Platform/NewsFolder.

Wildcard URLs seemed to be an option, but they are defined in CMSDesk, which, for the reason above, don't seem to be the best approach.

Any suggestions?

Thanks.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/9/2010 10:09:12 AM
   
RE:Choose template according to URL
Hi,

I would not recommend to do this because when changing the template, you will lose all the web parts and their settings on the document. But if you want to do this, you can use the custom event handler and add the logic for changing page template for given document in appropriate event.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
ricardo.fiel - 2/11/2010 6:28:29 AM
   
RE:Choose template according to URL
Hi, thanks for the answer.

That was my first idea, but I didn't really liked it. I don't have a problem with webparts, as I'm not using them (it's 100% aspx templates). It's just the idea of having too much in custom event handlers makes me feel like something's wrong with our design... oh well, it's the first website and a very large one. For sure, we'll improve over time :)

Thanks.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/15/2010 4:45:05 AM
   
RE:Choose template according to URL
Hi,

Your need is very specific and is not supported by default, therefore you need to do this kind of customization.

Best Regards,
Juraj Ondrus