Copied to clipboard

Flag this post as spam?

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


  • Profiterole 232 posts 264 karma points
    Feb 28, 2012 @ 02:59
    Profiterole
    0

    Get template currentNode template Name or Id

    Hi guys, I'm trying to get the current node's template name or id to select a diffrent css class.

    <% if(umbraco.presentation.nodeFactory.Node.GetCurrent().Template == "1046") { %>
    <div id="class1">
    <% } else { %>
    <div id="class2">
    <% } %>

    I'm begining all that stuff, so I'm not to sure about what I'm doing! What I want, it's to get the template Id and if it's 1046 apply css class1, else apply css class2.

    It's directly in my master page, and I use 4.7.1.

    Thank you for your help!

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 28, 2012 @ 10:16
    Lee Kelleher
    0

    Hi Profiterole,

    Quick fix: Set ".Template" to lowercase ".GetCurrent().template == " ... as that's the property name in the API call.

    Longer fix ... you could add a ContentPlaceHolder around the <div>, then override that in your selected template.  This is more the ".NET way" of doing it - also makes your template mark-up cleaner.  But that's just personal preference I guess! ;-)

    Cheers, Lee.

  • Profiterole 232 posts 264 karma points
    Feb 28, 2012 @ 14:02
    Profiterole
    0

    Hi Lee, I got an error about operand == and "int" or "string". I'll try the placeholder idea... that was my first idea too, but I was too lazy!

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 28, 2012 @ 14:44
    Lee Kelleher
    0

    With the error, try testing it as an 'int' instead of a 'string':

    <% if(umbraco.presentation.nodeFactory.Node.GetCurrent().template == 1046) { %>
  • Profiterole 232 posts 264 karma points
    Feb 28, 2012 @ 15:57
    Profiterole
    0

    Thank you

Please Sign in or register to post replies

Write your reply to:

Draft