Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi there,
<ul> @foreach(var item in Model.Parent.DescendantsOrSelf()){ <li><a href="@item.Url">@item.Name</a></li> }</ul>
I want to exclude specific descendants of my list. What to do?
Right now they're just being listed in one big list, but is it possible to list the descendants and childs like this:
http://ecigaret-info.dk/sitemap.aspx
I have tried several things from my Google searching for a few hours, and now my patience is up :(
I have tried something like this for Question 1:
var excludedDoctypes = new[] { "Teaser bokse", "Slide Mappe", "Webshop" };foreach (var childNode in Model.Parent.DescendantsOrSelf()){ if (!excludedDoctypes.Contains(childNode.NodeTypeAlias)) { <li><a href="@childNode.Url">@childNode.Name</a></li> }}
Totally wrong?
It's almost correct. You just need to cast "childNode.NodeTypeAlias" as a string like this:
if (!excludedDoctypes.Contains((string)childNode.NodeTypeAlias))
For your second question i would do like this:
@GetContentRecursive(Model.Parent)@helper GetContentRecursive(dynamic node) { var excludedDoctypes = new[] { "Teaser bokse", "Slide Mappe", "Webshop" }; <ul> @foreach(var childNode in node.Children){ if (!excludedDoctypes.Contains((string)childNode.NodeTypeAlias)) { <li> <a href="@childNode.Url">@childNode.Name</a> @if (childNode.Children.Count() > 0) { @GetContentRecursive(childNode) } </li> } } </ul> }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Get Children-list, and then exclude specific childrens
Hi there,
I have got a razor macro for a sitemap, which look like this:
<ul>
@foreach(var item in Model.Parent.DescendantsOrSelf()){
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
Question 1:
I want to exclude specific descendants of my list. What to do?
Question 2:
Right now they're just being listed in one big list, but is it possible to list the descendants and childs like this:
http://ecigaret-info.dk/sitemap.aspx
I have tried several things from my Google searching for a few hours, and now my patience is up :(
I have tried something like this for Question 1:
var excludedDoctypes = new[] { "Teaser bokse", "Slide Mappe", "Webshop" };
foreach (var childNode in Model.Parent.DescendantsOrSelf())
{
if (!excludedDoctypes.Contains(childNode.NodeTypeAlias))
{
<li><a href="@childNode.Url">@childNode.Name</a></li>
}
}
Totally wrong?
It's almost correct. You just need to cast "childNode.NodeTypeAlias" as a string like this:
if (!excludedDoctypes.Contains((string)childNode.NodeTypeAlias))
For your second question i would do like this:
@GetContentRecursive(Model.Parent)
@helper GetContentRecursive(dynamic node) {
var excludedDoctypes = new[] { "Teaser bokse", "Slide Mappe", "Webshop" };
<ul>
@foreach(var childNode in node.Children){
if (!excludedDoctypes.Contains((string)childNode.NodeTypeAlias))
{
<li>
<a href="@childNode.Url">@childNode.Name</a>
@if (childNode.Children.Count() > 0)
{
@GetContentRecursive(childNode)
}
</li>
}
}
</ul>
}
is working on a reply...