Forum

Thread tagged as: Question

List detail pages in navigation

Is there any way of automatically adding the detail page links generated from a list and detail setup to perch navigation?

Richard Lowe

Richard Lowe 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

No automatic way currently. They're not actually pages, so they don't appear. The only way is manually - generate the HTML and pass it into the template.

Simon Clay

Simon Clay 127 points

Hi Richard, I had to do this for a site which had it's products as 'list and detail' pages. I wanted to show the products listed in the main nav.

Here's how I did it:

First get the list of list and detail pages and pass them into a variable to be used on the nav, then show the nav on the page...

<?php 
    //find products and pass them into array
    $product_list = perch_content_custom('Product Details', array(
          'page' => '/our-range/products.php',
          'template' => '_products_in_nav.html',
          'include-parent' => true,
     ), true); 

    //set the array for use in the nav template
    PerchSystem::set_var('productlist', $product_list);

     //now we can output the nav
     perch_pages_navigation(array(
        'template' => array('level1.html', 'level2.html'),
        'hide-extensions' => 'true',
     ));
?>

I wanted the products to show in a dropdown from one of the main nav links, so, above you can see I have used two templates for nav: level1.html for the top-level and level2.html for the dropdown.

level1.html is fairly standard:

<li class="primary <perch:if exists="current_page"> active</perch:if><perch:if exists="ancestor_page"> ancestor</perch:if>">
    <a <perch:if exists="subitems">class="hasSubMenu"</perch:if> href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a>   
    <perch:pages id="subitems" encode="false" />
</li>

level2.html is where we call the variable that we set earlier:

<perch:before>
    <ul class="subMenu">
</perch:before>
        <li>
            <a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a>
            <perch:pages id="subitems" encode="false" />


        </li>
        <perch:if id="pagePath" match="eq" value="/our-range/ingredients"> <!--THE VALUE HERE IS WHERE I WANTED THE LIST AND DETAIL PAGES TO SHOW-->
            <perch:pages id="productlist" encode="false" /> <!--THIS CALLS IN THE VARIABLE WE SET-->
        </perch:if>
<perch:after>
    </ul>
</perch:after>

I hope that helps.

Richard Lowe

Richard Lowe 0 points
Registered Developer

Thankyou Simon and Drew, Currently I've just been adding them as pages with a link to the generated url. My client has multiple treatments which need to link to multiple conditions and vice-versa so I need each detail page to appear when using the 'pagelist' field. We have a system that works, but just wanted to know if there was an easier way.

Simon Clay

Simon Clay 127 points

Yes, I see.

The code above wouldn't add them to the pagelist field type.

But you could use dataselect to generate a list of those pages to choose from: https://docs.grabaperch.com/docs/templates/attributes/type/dataselect/

Richard Lowe

Richard Lowe 0 points
Registered Developer

Hmm, haven't used that before, that just might be perfick. Thanks!

Richard Lowe

Richard Lowe 0 points
Registered Developer

Worked Like a treat, thanks Simon!

Simon Clay

Simon Clay 127 points

Great! :)