umbraco - How do I display information in a foreach loop differently depending on the parent node's doc type? -


so i've got foreach loop displays list of nodes, , nested list of nodes under that. expand little nested list looks differently depending on doctype parent node has.

here's hierarchy of i'm working with:

  • directory (doctype directory landing)
    • players (doctype player folder)
      • tolkien
      • lewis
    • current characters (doctype player character folder)
      • katniss
    • npcs (doctype npc folder)
      • lando
    • past characters (doctype past character folder)
      • elrond
      • aslan

so want if statement, think, ask "if parent player folder, display name , picture of each node beneath it, if it's character folder, display name , picture , summary, if it's else, display name"). problem don't know how make check doctype is.

here's code have far:

<section id="directorylisting"> <ul>     @{         var logsnode = model.content.ancestororself("directorylanding");     }     @foreach (var node in logsnode.children.where("visible"))     {         <li>             <h2>@node.asdynamic().name</h2>             <ul>                 @foreach (var childnode in node.children)                 {                     <!-- if statement presumably begin here -->                     <li><!-- each section of if statement contain this-->                         <a href="@childnode.url">@childnode.name</a>                     </li>                     <!-- if statement presumably end here -->                 }             </ul>         </li>     } </ul> </section> 

something this:

<section id="directorylisting"> <ul>     @{         var logsnode = model.content.ancestororself("directorylanding");          foreach (var node in logsnode.children.where("visible"))         {             <li>                 <h2>@node.name</h2>                 <ul>                     @foreach (var childnode in node.children)                     {                         if (childnode.parent.documenttypealias == "character")                         {                             <li>                                 <a href="@childnode.url">@childnode.name</a>                             </li>                         }                         else if (childnode.parent.documenttypealias == "player")                         {                             <li>                                 <a href="@childnode.url">@childnode.name</a>                             </li>                         }                     }                 </ul>             </li>         }     } </ul> </section> 

Comments