Copied to clipboard

Flag this post as spam?

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


  • Morten 105 posts 345 karma points
    May 11, 2017 @ 07:59
    Morten
    0

    Composition property not found, but is found by inheritance

    I have a Document Type layout like this:

    Master
        News
        About us
    

    When I make a composition Document Type called "Hide elements" and I place that on News and About us, hasProperty() returns False.

    However, if I go to the Master Document Type and add a new tab called "Hide elements" and basically duplicate the composition, hasProperty() returns True.

    The problem here is, in my Master template file (where I have RenderBody()), I want to hide elements from that page, but only on pages where I check the "hide this element" property, if that makes sense.

    Something like this:

    <body>
        <header>
            @foreach (var item in CurrentPage.Site().Children) {
                 if (!item.GetPropertyValue<bool>("hideElement")) {
                      //do NOT hide the item
                  }
             }
        </header>
        @RenderBody()
    </body>
    

    I can do this fine by using inheritance (placing the property on my Master page), but it does not work with compositions. What am I doing wrong?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 11, 2017 @ 08:30
    Alex Skrypnyk
    0

    Hi Morten

    It's really strange, if you go to Umbraco backend, do you see the compositions' tab on your nodes?

    Maybe you need to republish Umbraco, because 'GetPropertyValue' method works with xml data.

    What version of Umbraco are you using?

    Thanks,

    Alex

  • Morten 105 posts 345 karma points
    May 11, 2017 @ 08:50
    Morten
    0

    Somehow it magically started working again. That's odd. Like something was cached. I didn't even republish the page or anything like that.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 11, 2017 @ 09:10
    Alex Skrypnyk
    0

    So, Morten, I think it was a problem with refreshing xml cache in Umbraco.

    Maybe some delay related to something.

    But generally, I'm glad that problem was solved.

  • Morten 105 posts 345 karma points
    May 11, 2017 @ 09:12
    Morten
    0

    Yeah me too. It made no sense why it wouldn't work.

    Is there a way to force refresh the cache?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 11, 2017 @ 09:13
    Alex Skrypnyk
    0

    It should refresh when you press save on doctype or save and publish on the document.

  • Morten 105 posts 345 karma points
    May 11, 2017 @ 09:14
    Morten
    1

    Oh hm, weird why that didn't work then. I guess I'll try to republish the whole page next time. Thanks :-)

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 11, 2017 @ 09:15
    Alex Skrypnyk
    1

    You are welcome!

    Have a nice day!

  • Morten 105 posts 345 karma points
    May 11, 2017 @ 09:52
    Morten
    0

    To you as well!

  • MrFlo 159 posts 403 karma points
    May 11, 2017 @ 08:43
    MrFlo
    0

    Hi Morten,

    You can make your foreach simpler:

    @foreach (var item in CurrentPage.Site().Children.Where("!hideElement"))
    {
        <p>@item.Name</p>
    }
    

    You don't even need to test for null or empty value.

    When you change the document type or add a property on the parent(master) page. You have to republish the site, this is mandatory or you will see multiple pages or errors.

  • Morten 105 posts 345 karma points
    May 11, 2017 @ 08:49
    Morten
    0

    What I did was just an example. Making it easier to read/less code does not make it work, though. Also, I did not make a property on the Master page. Try reading my post again :-)

  • MrFlo 159 posts 403 karma points
    May 11, 2017 @ 09:08
    MrFlo
    0

    To be honest I didn't understand properly your question "I make a composition Document Type called "Hide elements" and I place that on News and About us" You meant a property ?

    I was just suggesting that easier way to test a true/false property

  • Morten 105 posts 345 karma points
    May 11, 2017 @ 09:13
    Morten
    0

    No, I made a Document Type called "Hide elements", which has a bunch of properties on it. I then put that composition on the two sub pages.

Please Sign in or register to post replies

Write your reply to:

Draft