Thread tagged as: Question

Navigation Groups

Is there away to allow the admin to select the appropriate navigation group for different groups of 'products' using a generic 'product' page template?

Nick Loat

Nick Loat 0 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hi Nick,

Categories sound more appropriate to me here. You could have the admin add them to different categories and use perch_shop_products() to filter by category.

HI Hussein,

Unfortunately I'm not (currently using shop) I guesss what I was asking was whether its possible to pass a variable (the name of a navgroup) into the perch_pages_navigation array?

e.g. 'navgroup' =>'variablename',

You could do this by creating a custom field type for nav groups

I think this might be a little out of my league! As I'm a designer rather than a programmer. Is this something that you have done yourself?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

a generic 'product' page template

Do you create a new page for each product? If so, it might make sense to have the admins perform this through the page's settings.

Hi Hussein,

The products are buttons. Currently they are made out of three different materials. The are between 2-8 different styles/designs made in each material. Currently I have one 'product' template that consists of a main content area which displays the buttons of a given style/design and a sidebar in which I want to show the styles available made from the same material. I thought I could do this by asigning a 'style/design' to a navigation group based on its material at the point of creating the page. However I don't know how to allow the navigation group to be swapped out. As its set in the array of perch_pages_navigation() in the template.

 <?php perch_pages_navigation(array(
  'navgroup' =>'corozo',
  'template' => 'patterns.html',
  'levels' => 3
)); ?>

I currently got around this by creating page templates for each material, but this doesn't strike me as being very efficient and it also doesn't allow the admin to add new products made of a new material without first having to create a corresponding page template.

So my first though was is it possible to pass a variable into the array for the navgroup name?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

You certainly can use a variable here as long as it's a string.

'navgroup' => $navgroup,
'template' => 'patterns.html',
'levels' => 3

How you set the value of $navgroup can be done in different ways. If editors select the material on the product edit form, you probably want to use the value of that field.

Can you show us your template?

Hi Hussein, Sorry for the detail, I'vedbeen trying to figure this out… with no joy.

The variable I'm trying to use as the value for $navgroup is set in the region 'Pattern' that use the following template 'pattern-sample.html' and is the value of the 'catSlug'

<perch:categories id="material" label="Material" set="materials" required="true" max="1" order="1"  display-as="checkboxes"/>   
    <a href="/button-store.php">Button store</a> / <a href="/button-store/<perch:category id="catSlug" />-buttons.php"><perch:category id="catTitle" /> buttons

    <perch:content id="design" type="dataselect" label="Pattern" page="/product-list.php" region="product list" options="patternName" order="2" values="title" />   

<perch:repeater id="buttons" label="Buttons"/>      
<div class="pattern">

    <div class="button">
        <div class="area">
        <img src="<perch:content id="button" type="image" label="Button image" help="Size: ?? (@72dpi)" bucket="Buttons" order="5"/>" alt="" />
        <p class="colourname"><perch:content id="colour" type="text" label="Colour" order="6"/></p>


Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

You are using a self-closing perch:categories tag, so your perch:category tags here don't output anything. Use perch:categories as a pair tag instead like so (removed HTML for clarity):

<perch:categories id="material" label="Material" set="materials" required="true" max="1" order="1" display-as="checkboxes">
    <perch:category id="catTitle" />
    <perch:category id="catSlug" />

To get the value of catSlug on your page.php (assuming you are using a single-item region):

// return the HTML output of the Pattern region, this doesn't output the region.
$pattern_html = perch_content('Pattern', true);

// return content of the Pattern region in an array
$pattern_array = perch_content_custom('Pattern', [

// get catPath
$pattern_catPath = $pattern_array['material'][0];

$pattern_array would contain catPath, but not catSlug.

Option A: find catSlug from the catPath string:

$pattern_catPath_array = explode('/', $pattern_catPath);
$pattern_catSlug = $pattern_catPath_array[count($pattern_catPath_array)-2];

Option B: you can create a template templates/categories/category_slug.html and use perch_category() to get catSlug.


<perch:category id="catSlug" type="slug" />


$pattern_catSlug = perch_category($pattern_catPath, [
], true);

Now you can output the region and navigation in whatever order you want. page.php:

// navigation
    'navgroup' => $pattern_catSlug,
    'template' => 'patterns.html',
    'levels' => 3

// Pattern region
echo $pattern_html;

Hope this helps!

Hussein, incredible! Perfect. You're a star thank you.