forked from umbraco/UmbracoDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSiteMap.cshtml
38 lines (28 loc) · 1.04 KB
/
SiteMap.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
@* Walk up the tree from the current page to get the root node *@
var rootNode = Model.AncestorOrself(1);
}
@*Render the sitemap by passing the root node to the traverse helper*@
<div class="sitemap">
@traverse(@Model.AncestorOrSelf())
</div>
@*Helper method to travers through all descendants*@
@helper traverse(dynamic node){
@*If a MaxLevelForSitemap parameter is passed to the macro, otherwise default to 4 levels*@
var maxLevelForSitemap = String.IsNullOrEmpty(Parameter.MaxLevelForSitemap) ? 4 : int.Parse(Parameter.MaxLevelForSitemap);
@*Select visible children *@
var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
@*If any items are returned, render a list *@
if (items.Any()) {
<ul>
@foreach (var item in items) {
<li class="[email protected]">
<a href="@item.Url">@item.Name</a>
@*Run the traverse helper again *@
@traverse(item)
</li>
}
</ul>
}
}