Reputation: 53
I have a document type with alias dArticlesMain, and for this page I have the following structure.
dArticlesMain
dArticlesCategory1
dArticlesCategory2
dArticlesCategory3
I'm on dArticlesMain and i want to display all the descendants (Articles) and skip it's childrens (dArticlesCategory)
I have this code which display all the childrens (dArticlesCategory) and the descendants (Articles) also when i use the Article properties it's through an error.
<ul>
@foreach(var page in Model.Content.Descendants())
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
I have got this code but i can't display by Article properties like articleText or articleImage.
<ul>
@foreach(var page in Model.Content.DescendantsOrSelf().OfTypes("Article"))
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
Upvotes: 1
Views: 891
Reputation: 53
I have figured it out, and here's my code...
@{
var rootNode = CurrentPage.AncestorOrSelf(1);
var articlesParent = rootNode.Children("dArticlesMain").FirstOrDefault();
<div class="row">
@foreach (var article in articlesParent.Descendants("article").Where("Visible").RandomOrder())
{
<div class="col-sm-6 col-md-3">
<div class="thumbnail">
<a href="@article.Url">
<img src="@article.articlePhoto" alt="@article.articleName" />
</a>
<div class="caption">
<a class="h4" href="@article.Url">@article.articleName</a>
@Umbraco.Truncate(article.articleFullText, 100)
</div>
</div>
</div>
}
</div>
}
Upvotes: 1