Would it be possible to render a given umbraco node with different templates by applying custom logic?
Suppose there is a DocumentType called Product with a ProductType property. Based on the ProductType property a different template should be used to render that Product (eg. a course, hardware or software).
I explored the option to have only one template and render a Partial based on the ProductType property. Works fine but using templates would have a positive effect on the maintanance and configuration.
Render a node with different templates run-time
Would it be possible to render a given umbraco node with different templates by applying custom logic?
Suppose there is a DocumentType called Product with a ProductType property. Based on the ProductType property a different template should be used to render that Product (eg. a course, hardware or software).
I'm aware of the alttemplate function in Umbraco, but this affects the naming of the URL, and for SEO reasons I don't want to include that logic in the URL. (eg. the url http://mysite/a-category/a-product should remain like that and not become http://mysite/a-category/a-product/with-a-different-template).
I explored the option to have only one template and render a Partial based on the ProductType property. Works fine but using templates would have a positive effect on the maintanance and configuration.
I'm using Umbraco 7.1.8.
Hello,
You could try a content finder. Based on the url you can return a node and template. Here is an example: https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/blob/master/Umbraco.Extensions/ContentFinder/NewsContentFinder.cs#L69
Jeroen
How complicated, Jeroen. :) How about /a-product/template-name
So if you have a template named News then by going to /a-product/news you get the product rendered with the news template.
Found that, Sebastiaan. But what if I want to avoid the /news suffix and apply the template conditionally?
Sebastiaan his alt template suggestion is easier, but you can't avoid the /news suffix with that.
Jeroen
Ah, I clearly didn't read.. Ignore me and listen to Jeroen. :-)
No worries Sebastiaan, open for all suggestions ;-)
is working on a reply...