Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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"/>
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.
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:
<umbraco:Item runat="server" field="template"/>
but that'll only get you the id of the template.
On the other hand, using the api, you could instantiate the template using:
Template templ = new Template(id);
and get the name of the template using
var templateName = templ.Text;
Hope this helps.
Is there any specific reason why you'd need the name of the template?
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
Thanks again all!!!!!!!!
FYI in XSLT you can get the template alias by using name() function. E.g. to count children of all but some templates
count(child::node()[name() != 'templateAlias')
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:
<xsl:choose> <xsl:when test="$currentPage/@template=ucomponents.cms:GetTemplateIdByAlias('HomePage')"> <xsl:value-of select="'Home Page'"/> xsl:when> <xsl:when test="$currentPage/@template=ucomponents.cms:GetTemplateIdByAlias('TextPage')"> <xsl:value-of select="'Text Page'"/> xsl:when> xsl:choose>
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...
Write your reply to:
Image will be uploaded when post is submitted