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.
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
}
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.
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:
Hope this helps :)
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")
is working on a reply...