Forum

Thread tagged as: Question, Problem

Dynamic Navgroup?

I have this in my page template (below). Is it possible to make the 'navgroup' => 'navgroup choosen in backend?' to display only pages link that are in the navgroup? Instead of creating different page templates.

<?php
perch_pages_navigation(
array(
'navgroup' => 'bohol',
'template' => 'navgroup.html',
'from-path' => '/'
));
?>
Edward Johansen

Edward Johansen 0 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Edward,

It's not 100% clear what you are asking, but it sounds like you don't want to hardocde the value of navgroup?

perch_pages_navigation([
'navgroup' => $navgroup,
'template' => 'navgroup.html',
]);

The value can be dynamic. You can add it however you want. For example:

Content region:

$navgroup = perch_content('Navigation Group', true);

Page attribute:

$navgroup = perch_page_attribute('navgroup', [], true);

Thank you for the replay. Yes, I don't want to hardcode the navgroup value.

How can I give a custom template below? So I don't have to select a template everytime. Perhaps a dropdown select option?

$navgroup = perch_content('Navigation Group', true);
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

It's up to you how you want to set it up. You can provide a single text field and enter the text manually. Or use a single select field.

On your page you'd need:

$navgroup = perch_content('Navigation Group', true);

perch_pages_navigation([
'navgroup' => $navgroup,
'template' => 'navgroup.html',
]);

And in your template you can use a select:

<perch:content id="navgroup" type="select" label="Navigation Group" options="header,footer,bohol" >

OK. Thanks Hussein.