Copied to clipboard

Flag this post as spam?

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


  • Nick 97 posts 514 karma points
    Apr 18, 2023 @ 13:42
    Nick
    0

    Checking boolean value

    Hi,

    I have a small ask, I'm using a true/false data type to show and hide a section on the page the code is below which kind of works, but the default off selection is hiding all the content rather than when the value is true then hide it, is it possible to swap around the values so:

    False is show content by default True is hide content

    @if (Model.HideAboutSection)
    {
        <div class="section extrainfo">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12">
                        @Model.Value("aboutCompanyInfo")
                    </div>
                </div>
            </div>
        </div>
    }
    

    enter image description here

    Again thanks for all the Umbraco support :-)

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Apr 18, 2023 @ 16:14
    Marc Goodson
    100

    Hi Nick

    Do you mean like this

    @if (!Model.HideAboutSection)
    {
    

    eg you just want to reverse the logic here??

    or are you hitting a common pitfall where you have added the Checkbox to existing published pages?

    If so it is the absence of the checkbox in the published cache that is being transformed as 'false' rather than any default value.

    if this is the case then you can check whether the property exists in the cache via:

    Model.HasProperty("hideAboutSection")

    and then you could have

    if (!Model.HasProperty("hideAboutSection") || !Model.HideAboutSection)

    and it would show the section by default for all pages or if the checkbox isn't ticked to hide the section.

    God it does your head in to think about 'hide' and 'not hide' so hopefully that is explained correctly way around!

    regards

    Marc

  • Nick 97 posts 514 karma points
    Apr 26, 2023 @ 05:05
    Nick
    0

    Brilliant!

    Thanks Marc your solution worked exactly as expected.

    Many thanks

Please Sign in or register to post replies

Write your reply to:

Draft