Im looking for some help with my navigation partial.
I have a multiple nodes with the document type "services" that should not appear in the navigation.
Any help on how I should hide theses from the navigation would be grateful.
Thanks
Martin
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ var home = CurrentPage.Site(); }
@if (home.Children.Any())
{
@* Get the first page in the children *@
var naviLevel = home.Children.First().Level;
<nav class="nav">
@* Add in level for a CSS hook *@
<ul id="cd-primary-nav" class="level-@naviLevel">
@* For each child page under the home node *@
@foreach (var childPage in home.Children.Where("Visible"))
{
if (childPage.Children.Any())
{
<li class="has-children @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
<a href="@childPage.Url">@childPage.Name</a>
@childPages(childPage.Children)
</li>
}
else
{
<li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
<a href="@childPage.Url">@childPage.Name</a>
</li>
}
}
</ul>
</nav>
}
@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="sublevel level-@(naviLevel) ">
@foreach (var page in pages)
{
<li>
<a class="item" href="@page.Url">
<p>@page.Name</p>
</a>
@* if the current page has any children *@
@if (page.Children.Any())
{
@* Call our helper to display the children *@
@childPages(page.Children)
}
</li>
}
</ul>
}
}
On your document type for the services pages. Just add a new property with the alias of umbracoNaviHide, and set the type to be true/false, this should do it.
So when it´s checked, the pages with the propperty is checked, the page should not appear in the navigation.
Or if you want to do programmably it can be done like this:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ var home = CurrentPage.Site(); }
@if (home.Children.Any()) { @* Get the first page in the children *@ var naviLevel = home.Children.First().Level;
<nav class="nav"> @* Add in level for a CSS hook *@ <ul id="cd-primary-nav" class="level-@naviLevel"> @* For each child page under the home node *@ @foreach (var childPage in home.Children.Where("Visible")) { if (childPage.Children.Any()) { <li class="has-children @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
@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="sublevel level-@(naviLevel) ">
@* if the current page has any children *@ @if (page.Children.Any()) { @* Call our helper to display the children *@ @childPages(page.Children) } </li> } </ul> } }
Remember to change the bold linie, so it match your document type alias for the service pages.
Hope this helps, if you have other questions don't hesitate to ask again
Hi Dennis,
Thanks, yeah I have that set up for one off pages. Ideally I would need it to automatically hide any page with a "services" document type. I could leave it with umbracNaviHide, but content editors will forget to hide the pages.
Try to see my comment above your latest. There is how you can do it automatically. If it gives you any problems feel free to ask again, and I would try to help you out.
Navigation - Hide document types from nav
Hi,
Im looking for some help with my navigation partial.
I have a multiple nodes with the document type "services" that should not appear in the navigation.
Any help on how I should hide theses from the navigation would be grateful.
Thanks
Martin
Hi Martin,
On your document type for the services pages. Just add a new property with the alias of umbracoNaviHide, and set the type to be true/false, this should do it.
So when it´s checked, the pages with the propperty is checked, the page should not appear in the navigation.
Hope this helps,
/Dennis
Hi Martin
Or if you want to do programmably it can be done like this:
Remember to change the bold linie, so it match your document type alias for the service pages.
Hope this helps, if you have other questions don't hesitate to ask again
/Dennis
Hi Dennis, Thanks, yeah I have that set up for one off pages. Ideally I would need it to automatically hide any page with a "services" document type. I could leave it with umbracNaviHide, but content editors will forget to hide the pages.
Hi Martin,
Try to see my comment above your latest. There is how you can do it automatically. If it gives you any problems feel free to ask again, and I would try to help you out.
/Dennis
Hey Dennis, sorry I posted at the same time.
Thanks, it works great.
One last question, if I had multiple document types that I wanted to exclude, how would I tackle that?
Thanks again.
Hi Martin,
That´s no problem, you can exclude multiple document types using the following syntax,
Hope this helps,
/Dennis
is working on a reply...