Access Parent Node property in Child Template View MVC Razor in Umbraco 8.1.0
Hello All,
I have one articles list (parent node) and article detail (child node) document type. In article list document type I have taken Header section background image, HeaderText and SEO modules property.
In article detail screen I have numbers of column like Article Name, Article date, Article Image, description property etc.
As per above I nested the article detail with article list and using query builder I render article list in front-end with order by descending created date. Please refer below query.
But my requirement is I need display article list based on article date which property available in article detail page. so problem with query builder I can`t access children property in where condition and set the list in order by descending with article date property. So any one know how to access children property in MVC RAZOR of Umbraco 8.1.0 version.
Second problem is I can`t access parent Header Background Image in child template view just like
So if you have solution about this can you please help me so I can work with common component without add every time new property child node.
and in your article template page, if you want to read the property from the article list document type, you can use 'Fallback.ToAncestors' which will recurse up the content tree until it finds a property of that alias that is populated:
@{
var newsListBackgroundImage = Model.Value<IPublishedContent>("backgroundImage", fallback: Fallback.ToAncestors)
}
Access Parent Node property in Child Template View MVC Razor in Umbraco 8.1.0
Hello All,
I have one articles list (parent node) and article detail (child node) document type. In article list document type I have taken Header section background image, HeaderText and SEO modules property. In article detail screen I have numbers of column like Article Name, Article date, Article Image, description property etc.
As per above I nested the article detail with article list and using query builder I render article list in front-end with order by descending created date. Please refer below query.
var section = Umbraco.Content(Guid.Parse("7c4e163e-cd41-42c1-af3e-26bfd0530d7c")) .ChildrenOfType("createArticle") .Where(x => x.IsVisible()) .OrderByDescending(x => x.CreateDate)
But my requirement is I need display article list based on article date which property available in article detail page. so problem with query builder I can`t access children property in where condition and set the list in order by descending with article date property. So any one know how to access children property in MVC RAZOR of Umbraco 8.1.0 version.
Second problem is I can`t access parent Header Background Image in child template view just like
So if you have solution about this can you please help me so I can work with common component without add every time new property child node.
Thanks in Advance.
Hi Mihir
Would I be write in thinking you are after something like this?
and in your article template page, if you want to read the property from the article list document type, you can use 'Fallback.ToAncestors' which will recurse up the content tree until it finds a property of that alias that is populated:
regards
Marc
Thanks Marc Goodson,
Its work both solutions I can easily access parent - child property in list and access parent image in child view.
Again Thank you so much for quick response.
Great Mihir! - glad that you have gotten it working!
is working on a reply...