Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 03, 2012 @ 14:47
    Fuji Kusaka
    0

    Check Document Type when using traverse

    Hi Guys,

    Can someone point out that am doing wrong here ? Am trying to display a css class depending on the nodeTypeAlias using Traverse for a navigation.

    Here is my code snippet. Any suggestion please?

     foreach(var list in companyList){          
                <div>   
       <ul>
                        <li><a href="#" class="@Library.If((list.AncestorsOrSelf("Company"))), "header", " ") @list.companyList">@list.Name</a> @traverse(list)</li>
                    </ul>     
            </div>
            }

  • Dan Diplo 1505 posts 5911 karma points MVP 4x c-trib
    Oct 03, 2012 @ 16:44
    Dan Diplo
    0

    You can use IsAncestorOrSelf to check whether a node is an ancestor of your current page like this:

    foreach (dynamic page in pages)
    {                 
        <[email protected](page.IsAncestorOrSelf(Model), "class=\"selected\"")>@page.Name
        </li>
    }

    I'm not quite sure what you are trying to check? What condition do you want the class to be headed?

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 03, 2012 @ 19:27
    Fuji Kusaka
    0

    Hi Dan,

    Thanks for the response but this is not what am trying to achieve here. Under a folder content i have several pages and some has child nodes.

    So the parent node lets say has a NodeTypeAlias(x) and its Child NodeTypeAlias(y). What i want to achieve here is get a UL list like this

    <ul>
    <li><a href="#" class="header">PageName</a>
    <ul>
    </li><a href="#" class="">SubPage Name </a></li>
    </ul>
    </li>
    </ul

    i know who to get this using a typical foreach loop and checking if Children.Count() > 0, but i would like make use of traverse here, so whenever it gets the parent node with nodeTypeAlias(x) it shows header and if not then a blank class

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 03, 2012 @ 20:34
    Fuji Kusaka
    0

    Got it working, but somehow not the best solution using @helper traverse

    <a href="#" class="@Library.If((list.NodeTypeAlias =="Company"), "header","") @list.companyList">@list.Name</a> @traverse(list)

     

    //fuji

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies