umbraco6 - Need help on dynamically creating navigation links based on content created in Umbraco -


i new in umbraco cms , started coding in recently. page structure thisenter image description here

and have written code generate dynamic navigation based on code have found in umbraco forums. in output giving 'home' link not other links.the reason have written { var homenode = model.ancestororself(1); } , returning home page not other pages. have tried using model.ancestororself(). giving same result.

<nav>     <ul>          @{ var homenode = model.ancestororself(1); }          <li><a href="@homenode.url" class="@library.if(homenode.id == model.id, "selected", "")">@homenode.name</a></li>          @foreach (var page in model.children.where("visible"))         {             var isselected = false;             if (model.id == page.id || (model.parent != null && model.parent.id == page.id && model.nodetypealias != "textpage"))             {                 isselected = true;             }              <li>                 <a href="@page.url" class="@library.if(isselected, "selected", "")">@page.name</a>                  <!-- if page has child nodes (2nd level) visible , doctypealias textpage (textpages) -->                 @if (page.textpages.where("visible").count() > 0)                 {                     <ul>                         @foreach (var childpage in page.children.where("visible"))                         {                             <li><a href="@childpage.url" class="@library.if(childpage.id == model.id, "selected", "")">@childpage.name</a></li>                         }                     </ul>                 }             </li>         }     </ul> </nav> 

what proper expression traverse this.

thanks , regards

utpal

right first thing want change site hierarchy this:

home |-- |-- contact |-- services 

you can find in document types, under settings in home node's document type, structure tab add allowed node children node types make home node have allowed children of 3 types have.

next you'll want code reach home node:

var homenode = model.content.ancestororself("site"); 

where "site" home node's document type.

next can prepare data you'll want loop:

var menuitems = homenode.children.where(x => x.isvisible()); 

finally can change loop this:

@foreach (var page in menuitems) 

this should work.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -