Copied to clipboard

Flag this post as spam?

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


  • Dennis Milandt 190 posts 517 karma points
    Jun 08, 2010 @ 17:27
    Dennis Milandt
    0

    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

  • Dennis Milandt 190 posts 517 karma points
    Jun 08, 2010 @ 17:42
    Dennis Milandt
    0

    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

  • Chris Dunn 210 posts 401 karma points
    Jun 08, 2010 @ 20:48
    Chris Dunn
    0

    Dennis,

    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);

    Namespaces have been included for the example.

    You can then check the template alias.

    -Chris

     

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Jun 08, 2010 @ 20:58
    Lee Kelleher
    0

    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.

     

  • Chris Dunn 210 posts 401 karma points
    Jun 08, 2010 @ 21:28
    Chris Dunn
    2

    Lee,

    umbraco.library.PageElement isn't a static function so you would need to pass the nodeid to the constructor.

     

    string template = (new umbraco.library(Request["id"]).PageElement["template"];

     

     -Chris

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Jun 09, 2010 @ 09:14
    Lee Kelleher
    0

    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.

  • Dennis Milandt 190 posts 517 karma points
    Jun 09, 2010 @ 14:03
    Dennis Milandt
    0

    Thanks a lot :-) Just what I needed.

    /Dennis

  • 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