If i use FirstOrDefault() it always takes the logo from the home node,if i use LastOrDefault i outputs nothing on fx the item "Mypage.aspx" because i havent added a logo to this item, cuz it should inherit it from "Entrance1"?
By adding the underscore in front of the property name, you're also saying that you want it recursively. However, there MIGHT be a bug in 4.7.1 preventing either Tom's or my solution to work, so try it out and if it doesn't work, 4.7.1.1 (with a fix) should be out this week.
The underscore in front of the Razor property name is something I wished I had known about a while ago. I only very recently learnt this after picking it up as a short aside in one of the "what's new in v5 beta" posts. I don't recall seeing it in any of the Umbraco TV episodes or anywhere else fairly obvious so it does seem like a nice secret to know!
Thx for the answers - Didn't know about the underscore in front of the property name :) Kindda funny, but easy way to say that you awnt something recursively...
In 4.7.1.1 this seems to return empty strings if it hits a node with the property but no value set - is this by design and how do you work around it telling it to only return a property that has a real value set?
Same issue here using Model.GetPropertyValue("prop", true) - but Sebestiaan's method still seems to work fine I believe - Model._prop. Is that working for you also? Sounds like a bug, maybe we can check with @agrath
Get logo recursively wont work?
Hey guys...
Im trying to get a logo recursively - however, it wont work as i want it to...
I have 4 entrances
Home
- Entrance1
- A page
- Entrance2
- Entrance3
- Entrance4
Each entrance has it's own logo added, so it should overwrite what is on the home node - However it doesnt...
My code looks like
@inherits umbraco.MacroEngines.DynamicNodeContext
@if (Model.AncestorOrSelf().HasProperty("siteLogo")){
<a class="logo" href="/"><img src='@Model.AncestorsOrSelf().FirstOrDefault().Media("siteLogo", "umbracoFile")' /></a>
} else {
<a class="logo" href="/"><img src='@Model.Media("siteLogo", "umbracoFile")' /></a>
}
Hi,
You could try something like this instead. The true on GetPropertyValue indicates it should get the value recursively:
-Tom
Or, even easier:
By adding the underscore in front of the property name, you're also saying that you want it recursively. However, there MIGHT be a bug in 4.7.1 preventing either Tom's or my solution to work, so try it out and if it doesn't work, 4.7.1.1 (with a fix) should be out this week.
The underscore in front of the Razor property name is something I wished I had known about a while ago. I only very recently learnt this after picking it up as a short aside in one of the "what's new in v5 beta" posts. I don't recall seeing it in any of the Umbraco TV episodes or anywhere else fairly obvious so it does seem like a nice secret to know!
Good luck!
Thx for the answers - Didn't know about the underscore in front of the property name :) Kindda funny, but easy way to say that you awnt something recursively...
For those interested, there is a very good razor DynamicNode cheatsheet available at http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet with lots of other interesting stuff :-)
Cheers,
Michael.
In 4.7.1.1 this seems to return empty strings if it hits a node with the property but no value set - is this by design and how do you work around it telling it to only return a property that has a real value set?
Same issue here using Model.GetPropertyValue("prop", true) - but Sebestiaan's method still seems to work fine I believe - Model._prop. Is that working for you also? Sounds like a bug, maybe we can check with @agrath
I remember there was a problem with the AncestorOrSelf call that should've been fixed in 4.7.1.1, but Model._prop should indeed work.
Underscore trick did it - thanks.
is working on a reply...