Last active
April 11, 2022 22:53
-
-
Save markadrake/af8bf03d5d61e296883447bd5d4b9b68 to your computer and use it in GitHub Desktop.
Umbraco 9 | Sitemap in Razor
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
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage | |
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels; | |
@{ | |
Layout = "template.cshtml"; | |
var currentPage = Umbraco.AssignedContentItem; | |
var root = currentPage.AncestorOrSelf(1); | |
} | |
<div class="sitemap"> | |
<ul> | |
@foreach(var page in root.Children()) { | |
listChildren(page); | |
} | |
</ul> | |
</div> | |
@functions { | |
public void listChildren(IPublishedContent page) { | |
var children = page.Children(); | |
<li> | |
<a href="@(page.Url())">@(page.Name)</a> | |
@if(children.Any()) { | |
<ul> | |
@foreach(var child in children) { | |
listChildren(child); | |
} | |
</ul> | |
} | |
</li> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does the tab spacing look like shit? That's because GitHub defaults to 8 spaces! You can change this default by visiting the appearance section of your profile.