Umbraco & Razor: If CurrentPage/Model is a Child, condition -
my navigation/node construction follows:
home --about us --our services -----finance -----insurance
my current code loops through nodes , lists them in . when 'currentpage' has children, menu includes children.
the problem loop when 1 of children (finance or insurance) 'currentpage', 'if' status on 'our services' node fails th currentpage no longer has children, hence 'finance' , 'insurance' longer remain in menu.
i want add together me 'if', '||' clause 'or currentpage kid node'
code below thanks
<ul> @foreach (var page in @currentpage.ancestororself(1).children) { <li class="menuitems @(page.isancestororself(currentpage) ? "selected" : null)"> <a href="@page.url">@page.name test</a> </li> if (@currentpage.children.count() > 0) { foreach (var childpage in page.children) { <li class="menuitems menuchilditems @(childpage.isancestororself(currentpage) ? "selected" : null)"> <a href="@childpage.url">@childpage.name</a> </li> } } } </ul>
the first foreach should home. (is home @ level 1?)
there no need if(has children) check, because if there isn't children, not loop.
do want 2 levels of menus? if so, this:
<ul> @foreach (var page in currentpage.ancestororself(1).children) { <li class="menuitems @(page.id == currentpage.id ? "selected" : "")"> <a href="@page.url">@page.name test</a> </li> @if(currentpage.id == page.id || currentpage.parent.id == page.id) { foreach (var childpage in page.children) { <li class="menuitems menuchilditems @(childpage.id == currentpage.id ? "selected" : "")"> <a href="@childpage.url">@childpage.name</a> </li> } } } </ul>
razor umbraco
No comments:
Post a Comment