Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • marcelh 171 posts 471 karma points
    Oct 27, 2014 @ 16:14
    marcelh
    0

    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.

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Oct 27, 2014 @ 18:29
    Jeroen Breuer
    0

    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

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Oct 27, 2014 @ 19:23
    Sebastiaan Janssen
    0

    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.

  • marcelh 171 posts 471 karma points
    Oct 27, 2014 @ 19:27
    marcelh
    0

    Found that, Sebastiaan. But what if I want to avoid the /news suffix and apply the template conditionally?

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Oct 27, 2014 @ 19:31
    Jeroen Breuer
    0

    Sebastiaan his alt template suggestion is easier, but you can't avoid the /news suffix with that.

    Jeroen

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Oct 27, 2014 @ 20:01
    Sebastiaan Janssen
    0

    Ah, I clearly didn't read.. Ignore me and listen to Jeroen. :-)

  • marcelh 171 posts 471 karma points
    Oct 27, 2014 @ 20:03
    marcelh
    0

    No worries Sebastiaan, open for all suggestions ;-)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies