我刚开始使用 Umbraco 7,我创建了 2 个文档类型和 3 个页面,
我正在使用从入门工具包下载的模板。
首先,为什么这么难理解这个平台?!?!我已经看过 Umbraco.tv 中的所有剪辑了。
第二个重要的问题是:为什么导航栏没有显示所有页面?看来我只有一页已经硬编码了..
这是模板的代码:
@inherits UmbracoTemplatePage
@{
// Model.Content is the current page that we're on AncestorsOrSelf is all of the ancestors this page has in the tree
// (1) means: go up to level 1 and stop looking for more ancestors when you get there First() gets the first ancestor found (the home page, on level 1)
var homePage = CurrentPage.AncestorsOrSelf(1).First();
var menuItems = homePage.Children.Where("UmbracoNaviHide == false");
}
<!-- Nav -->
<ul class="menu">
@* If the Url of the current page is "/" then we want to add the class "current_page_item" *@
@* Otherwise, we set the class to null, that way it will not even be added to the <li> element *@
<li class="@(CurrentPage.Url == "/" ? "sel" : null)">
<a href="/homepage">Home</a>
</li>
@foreach (var item in menuItems)
{
var childrenItems = item.Children.Where("UmbracoNaviHide == false");
<li class="@(CurrentPage.Id == item.Id ? "sel" : null)">
<a href="@item.Url">@item.Name</a>
@createSubmenu(childrenItems, item.Id)
</li>
}
</ul>
@helper createSubmenu(IEnumerable<IPublishedContent> nodes, int? parentId) {
if (nodes.Count() > 0){
<ul>
@foreach (var node in nodes)
{
var childrenItems = node.Children.Where("UmbracoNaviHide == false");
<li class="@(CurrentPage.Id == node.Id ? "sel" : null)">
<a href="@node.Url">@node.Name</a>
@createSubmenu(childrenItems, node.Id)
</li>
}
</ul>
}
}
<!-- /Nav -->