I have just started using Umbraco and am slowing getting to grips with it... so I am sure this is a pretty easy question. I wanted to know how I get the current template name and I am not sure of the field? e.g.
if you whant to retrive the current template by using API you can use this code:
int currentNodeId = umbraco.presentation.UmbracoContext.Current.PageId.Value; umbraco.presentation.nodeFactory.Node node = new umbraco.presentation.nodeFactory.Node(currentNodeId); umbraco.template t = new umbraco.template(node.template);
t.TemplateAlias is the alias name of the current template.
Thanks for your help; Dirk the template ID will be ideal and works fine. I need it because all the templates share the same master; I just need to handle different elements of the master differently for each template. I assume if I had an unique identifier for each template I could use JavaScript to control the elements.
getting a template alias
hello guys,
I have just started using Umbraco and am slowing getting to grips with it... so I am sure this is a pretty easy question. I wanted to know how I get the current template name and I am not sure of the field? e.g.
<umbraco:Item runat="server" field="TemplateName"/>
Thanks
Andy
if you whant to retrive the current template by using API you can use this code:
int currentNodeId = umbraco.presentation.UmbracoContext.Current.PageId.Value;
umbraco.presentation.nodeFactory.Node node = new umbraco.presentation.nodeFactory.Node(currentNodeId);
umbraco.template t = new umbraco.template(node.template);
t.TemplateAlias is the alias name of the current template.
Billi
Hi Andy,
I'm not sure why you'd need to get the name of the template... Anyways, you can't get that property from a document as it doesn't exist.
You could get to the id of the template using:
but that'll only get you the id of the template.
On the other hand, using the api, you could instantiate the template using:
and get the name of the template using
Hope this helps.
Is there any specific reason why you'd need the name of the template?
Regards,
/Dirk
The Umbraco XML cache does not contain the template alias (see http://our.umbraco.org/wiki/reference/umbraco-xml-format) it only contains the template ID.
You need to use the Umbraco API if you want more information about the template
Hello guys,
Thanks for your help; Dirk the template ID will be ideal and works fine. I need it because all the templates share the same master; I just need to handle different elements of the master differently for each template. I assume if I had an unique identifier for each template I could use JavaScript to control the elements.
Thanks again all!!!!!!!!
Cheers,
Andy
FYI in XSLT you can get the template alias by using name() function. E.g. to count children of all but some templates
I had the same question and found a solution with uComponents, so thought I'd add it to this post.
With uComponents installed you can use the following in xslt to get the template id from the template name:
For example you could do the following:
Hopefully this might be of help to someone else as the answer is now probably far too late for the original poster!
is working on a reply...