You can retrieve the current template by accessing the current node through the nodefactory, and then retrieve the template object of that node.
int tmplId = umbraco.presentation.nodeFactory.Node.GetCurrent().template; umbraco.cms.businesslogic.template.Template tmpl = new umbraco.cms.businesslogic.template.Template (tmplid);
Thanks for point that out Chris. I'd never used 'PageElement' method myself (yet). I was just browsing through the assemblies with Reflector. That will teach me! ;-)
Determine the template being used
Hi everybody,
Is there a way to determine which template is being used for a page when being rendered?
I have a master template and template 1 and template 2. The latter two are sub templates of the master template.
I have a document type which allows the use of both template 1 and template 2.
Can I in the master template code behind using the Umbraco API determine if the page is being rendered using template 1 or template 2?
Kind regards
Dennis Milandt
A little bonus info, and partial the answer to my question:
If the template is applied as an alternate template, you can look up the template used using umbraco.library.GetHttpItem("altTemplate")
Still need to figure out if the template is selected on the node in the Generic Properties tab in Umbraco though.
/Dennis
Dennis,
You can retrieve the current template by accessing the current node through the nodefactory, and then retrieve the template object of that node.
Namespaces have been included for the example.
You can then check the template alias.
-Chris
Take a look at...
umbraco.library.PageElement('template')... that will give you the Id of the template being used - including whether an 'altTemplate' has been used.
Cheers, Lee.
Lee,
umbraco.library.PageElement isn't a static function so you would need to pass the nodeid to the constructor.
-Chris
Thanks for point that out Chris. I'd never used 'PageElement' method myself (yet). I was just browsing through the assemblies with Reflector. That will teach me! ;-)
Cheers, Lee.
Thanks a lot :-) Just what I needed.
/Dennis
is working on a reply...
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.