Copied to clipboard

Flag this post as spam?

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


  • russell 1 post 71 karma points
    Jun 02, 2017 @ 17:11
    russell
    0

    Simple IF statement??

    Hi,

    I'm very new to Umbraco - with about 4 hrs experience, so sorry for what might be a 'silly question'

    So in my DocType I have added a True/False field.

    In my template I am then trying to show/hide content based on whether that value is True or False.

    I have tried a number of, what I hoped might be solutions, but they either don't appear to do anything or cause a runtime error.

    If I hardcode in

    @if ("True" == "True")
    {
     <div>Show me</div>
    }
    

    That seems to work.

    But if I replace the first value with the property? I am trying to check, not so good e.g..

    @if ("@Umbraco.Field("showBanner1")") == "True")
    
    {
     <div>Show Me</div>
    }
    

    or

    @if (Model.Content.GetPropertyValue("showBanner1") == "True")
    
    {
     <div>Show me</div>
    }
    

    I've even tried

    @{var show = @Umbraco.Field("showBanner1");}
    @{var show2 = @Umbraco.Field("showBanner1");}
    
    @if ("@show" == "@show2")
    
    {
     <div>Show Me</div>
    }
    

    So with the last one, even when I am checking the value against itself it doesn't appear to work, so I know I'm doing something wrong.

    Any help would be most appreciated.

    Thanks.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 05, 2017 @ 12:58
    Dennis Aaen
    100

    Hi Russel and welcome to our :)

    Could you please try the snippet of code below here.

    @if (Model.Content.GetPropertyValue<bool>("showBanner1"))
    
    {
     <div>Show me</div>
    }
    

    Then the div will be shown when you have ticked the true / false property on the page that you are viewing in the browser.

    Hope this helps,

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

    Continue discussion

Please Sign in or register to post replies