Autonav (jordanlev template) - display a page's custom attribute outside loop

Permalink
Hello all

I'm trying to create a custom mega nav which lists pages, then displays a thumbnail from the image attribute of one of those pages (defined by a separate boolean attribute) off to the right.

I can get the image to appear within the <li> of the page, but that's no use - I need it to be 'out of the loop' so I can position it to the right of the list.

I'm using @jordanlev's brilliant tidied up Autonav template, but I still can't work it out:

echo '<ul class="main-nav">'; //opens the top-level menu
foreach ($navItems as $ni) {
   echo '<li class="' . $ni->classes . '">'; //opens a nav item
   echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>';
   if ($ni->has_submenu) {
      echo '<div class="outside"><div class="inside">';   
      echo '<div class="links"><div class="inthisarea">In this area</div>';
      echo '<ul class="secondary">'; //opens a dropdown sub-menu
   } else {
      echo '</li>'; //closes a nav item
      echo str_repeat('</ul></div><div class="clear"></div></div></div></li>', $ni->sub_depth); //closes dropdown sub-menu(s) and their top-level nav item(s)
   }
   /*$thisPage = Page::getByID( $ni->cid );
      $featuredPrimary = ($thisPage->getCollectionAttributeValue('meganav_featured_primary')) ? true : false;
      if($featuredPrimary){


You can see what I've tried to do in the commented out section.

My problem lies with this line:

echo str_repeat('</ul></div><div class="clear"></div></div></div></li>', $ni->sub_depth); //closes dropdown sub-menu(s) and their top-level nav item(s)


I need the image to be displayed after the first '</ul></div>', but still within the total loop (because it needs to be within the top-level <li>, obviously). If I put in a hard-coded image it works, but I can't seem to put a dynamically-generated image in there. I need to be able to do it multiple times (for different drop-downs in the mega nav).

Anyone have any ideas?

melat0nin