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?
@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.
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 :-)
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
Composition property not found, but is found by inheritance
I have a Document Type layout like this:
When I make a composition Document Type called "Hide elements" and I place that on News and About us,
hasProperty()
returnsFalse
.However, if I go to the Master Document Type and add a new tab called "Hide elements" and basically duplicate the composition,
hasProperty()
returnsTrue
.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:
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?
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
Somehow it magically started working again. That's odd. Like something was cached. I didn't even republish the page or anything like that.
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.
Yeah me too. It made no sense why it wouldn't work.
Is there a way to force refresh the cache?
It should refresh when you press save on doctype or save and publish on the document.
Oh hm, weird why that didn't work then. I guess I'll try to republish the whole page next time. Thanks :-)
You are welcome!
Have a nice day!
To you as well!
Hi Morten,
You can make your foreach simpler:
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.
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 :-)
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
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.
is working on a reply...
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