Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1347 posts 1608 karma points
    Oct 13, 2011 @ 12:28
    Gordon Saxby
    0

    Can I get the Template Name from XSLT?

    I want to display the NAME of a template that a node is based on rather than its ALIAS - can I do that in XSLT?

    the name() function returns the alias - how can I get the name (name as entered for a template in the Developers section).

    If not with XSLT, can I do it via the API / C#?

  • Rodion Novoselov 694 posts 859 karma points
    Oct 13, 2011 @ 12:44
    Rodion Novoselov
    1

    Hello. A template name isn't accessible from Xslt directly. However, you can always add some C# (or VB.NET) script to your xslt with a msxml:script element. In your case you could use something like this:

      <msxml:script language="C#" implements-prefix="script">
        <msxml:assembly name="cms"/>
        <msxml:assembly name="businesslogic"/>
        <msxml:using namespace="umbraco.cms.businesslogic.template"/>
          public string GetTemplateTextById(int id) {
            return new Template(id).Text;
          }
      </msxml:script>

    and:

    <xsl:value-of select="script:GetTemplateTextById($currentPage/@template)"/>

     

  • Gordon Saxby 1347 posts 1608 karma points
    Oct 13, 2011 @ 13:46
    Gordon Saxby
    0

    I put the code into an XSLT Extension project ... and it works! Thanks for pointing me in the right direction :-)

     

  • Tom Fulton 2030 posts 4996 karma points c-trib
    Oct 13, 2011 @ 13:52
    Tom Fulton
    1

    FYI, there's also some XSLT extensions built into uComponents for accessing templates - GetTemplateById should work for you - see XSLT Extension - CMS

  • 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.

Please Sign in or register to post replies