Copied to clipboard

Flag this post as spam?

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


  • Lex Godthelp 15 posts 99 karma points
    May 28, 2018 @ 11:52
    Lex Godthelp
    0

    How to compare CurrentPage.Template to a number?

    Hi guys,

    I was wondering how i could compare CurrentPage.template to an id. For instance:

    @if(CurrentPage.template == "1079")
    

    The above statement does not give an error, but does not render properly. If i do it like so @if(!CurrentPage.template =="1079") it gives the error:

    Operator '==' cannot be applied to operands of type 'bool' and 'string'

    So i suppose it has trouble comparing the bool/string output from CurrentPage.template to a number.

    Any suggestions?

    Thanks in advance,

    Lex

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 28, 2018 @ 11:53
    Alex Skrypnyk
    100

    Hi Lex

    Are you going to check TemplateId?

    Use this code:

    if (Umbraco.AssignedContentItem.TemplateId == 1079)
    {
    
    }
    

    Alex

  • Lex Godthelp 15 posts 99 karma points
    May 28, 2018 @ 11:55
    Lex Godthelp
    0

    Hi Alex,

    That was exactly what i was trying to do. And this solution worked perfectly! You are the man!

    With kind regards,

    Lex

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 28, 2018 @ 11:55
    Alex Skrypnyk
    0

    You are welcome, Lex!

    Have a great day!

Please Sign in or register to post replies

Write your reply to:

Draft