forked from umbraco/UmbracoDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
perploug
committed
Aug 16, 2012
1 parent
dcd460a
commit e35f24b
Showing
2 changed files
with
40 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,38 @@ | ||
@inherits PartialViewMacroPage | ||
@using Umbraco.Cms.Web | ||
@using Umbraco.Cms.Web.Macros | ||
@using Umbraco.Framework | ||
@inherits umbraco.MacroEngines.DynamicNodeContext | ||
|
||
@{ | ||
@* Walk up the tree from the current page to get the root node *@ | ||
var rootNode = CurrentPage.AncestorsOrSelf.Last(); | ||
var rootNode = Model.AncestorOrself(1); | ||
} | ||
|
||
@* Ensure that the Root Node has children, where the property umbracoNaviHide is not True *@ | ||
@if (rootNode.Children.Where("umbracoNaviHide != @0", "True").Any()) | ||
{ | ||
@* Get the first page in the children, where the property umbracoNaviHide is not True *@ | ||
var naviLevel = rootNode.Children.Where("umbracoNaviHide != @0", "True").First().Level; | ||
|
||
@* Add in level for a CSS hook *@ | ||
<ul class="level-@naviLevel"> | ||
@* For each child page under the root node, where the property umbracoNaviHide is not True *@ | ||
@foreach (var childPage in rootNode.Children.Where("umbracoNaviHide != @0", "True")) | ||
{ | ||
<li> | ||
<a href="@childPage.Url">@childPage.Name</a> | ||
|
||
@* if the current page has any children, where the property umbracoNaviHide is not True *@ | ||
@if (childPage.Children.Where("umbracoNaviHide != @0", "True").Any()) | ||
{ | ||
@* Call our helper to display the children *@ | ||
@childPages(childPage.Children) | ||
} | ||
</li> | ||
} | ||
</ul> | ||
} | ||
@*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> | ||
|
||
@helper childPages(dynamic pages) | ||
{ | ||
@* Ensure that we have a collection of pages *@ | ||
if (pages.Any()) | ||
{ | ||
@* Get the first page in pages and get the level *@ | ||
var naviLevel = pages.First().Level; | ||
|
||
@* Add in level for a CSS hook *@ | ||
<ul class="level-@(naviLevel)"> | ||
@foreach (var page in pages.Where("umbracoNaviHide != @0", "True")) | ||
{ | ||
<li> | ||
<a href="@page.Url">@page.Name</a> | ||
|
||
@* if the current page has any children, where the property umbracoNaviHide is not True *@ | ||
@if (page.Children.Where("umbracoNaviHide != @0", "True").Any()) | ||
{ | ||
@* Call our helper to display the children *@ | ||
@childPages(page.Children) | ||
} | ||
</li> | ||
} | ||
</ul> | ||
@*Run the traverse helper again *@ | ||
@traverse(item) | ||
</li> | ||
} | ||
</ul> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters