Copied to clipboard

Flag this post as spam?

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


  • Mohan 5 posts 137 karma points
    Jun 03, 2016 @ 08:10
    Mohan
    0

    Alternate template identification through template Razor code.

    how to find alternate template names for a document type in umbraco 7 through programmatically.

    PROBLEM: Need to avoid certain Html elements in master page to render when the alternate template is of a specific.

    Ex: X document type contains two templates say Y (default template) and Z (alternate template). M is a master template for the site. Common Html that is in M need to be present in Y but not in Z.

  • Jordan 24 posts 182 karma points
    Jun 03, 2016 @ 08:20
    Jordan
    0

    Hey Mohan,

    Are you talking about inheriting from a master template? In which case you can tell Y to inherit from M (meaning the render.Body() in M will load content for Y). However during the template setup for Z you can set layout=null, this will stop Z taking any of the code from M.

    If you are needing certain elements from M still, then there really isn't a clean way of doing this. I would recommend moving the code out of M and placing what need to be in Y and what needs to be in Z. Or a more messy way would be to check the template alias of the current model on M and place the code you want to render inside that if statement, example:

    //On master template
    If (Model.Content.GetTemplateAlias() == "Z") {
        //html code to appear if template alias matches z
    }
    

    Hope this helps :)

  • Mohan 5 posts 137 karma points
    Jun 03, 2016 @ 11:02
    Mohan
    102

    Thanks Jordan,

    The solution you provided works only for default template but I need to know alternate templates for a specific document type.

    Anyways, I got the solution:

    @Request.Url.ToString().Contains("alternateTemplateAliasName")

Please Sign in or register to post replies

Write your reply to:

Draft