Forum

Thread tagged as: Problem

Navigation Issues

Hi all,

Relative newbie to Perch but loving it so far. Setup a couple of websites, however so far they have mostly just dealt with precreated pages that allow customers to edit regions in the page, that's been really straight forward.

However I've come into quite a big issue with regards master pages.

The issue is the navigation. As it stands, my current navigation is comprised of a list that contains quite a bit of php if statements, mostly used to add classes to assign 'selected'.

However, the navigation templates dont allow PHP to run, so I'm trying to get my head around how to do this without having to entirely restructure my websites navigation.

Any thoughts on this?

Here's a snippet of one of the li's in my nav.php and what I am trying to pass over to a template for the navigation folder, however the php cant be run from the html? :

<li <? if($section=="turicum") { echo 'class="hasSub selected"'; } else {echo 'class="hasSub"';} ?>>
            <a href="our-roots.php">Turicum</a>
            <ul <? if($section=="turicum") { echo 'class="subNav showSub"'; } else {echo 'class="subNav"';} ?>> 
                <li <? if($page=="ourroots") echo 'class="current"';?>><a href="our-roots.php">Our Roots</a></li>
                <li <? if($page=="ourclients") echo 'class="current"';?>><a href="our-clients.php">Our Clients</a></li>
                <li <? if($page=="investmentpolicy") echo 'class="current"';?>><a href="investment-policy.php">Investment Policy</a></li>
                <li <? if($page=="gibraltar") echo 'class="current"';?>><a href="gibraltar.php">Gibraltar</a></li>
            </ul>
</li>

What are the workarounds?

Natalia Robba

Natalia Robba 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do the current_page and ancestor_page options not cover this? There's an example in the default navigation template.

https://docs.grabaperch.com/templates/navigation/

Drew McLellan said:

Do the current_page and ancestor_page options not cover this? There's an example in the default navigation template.

https://docs.grabaperch.com/templates/navigation/

Hi Drew, many thanks for your reply. Yes actually, I suppose I could use the current_page to eliminate some of that php. Thing is there's some other php in use and I'm not sure to eliminate it, for example, as well as using a $page tag to grab the current page, I'm also using a $section tag. Perhaps erroneously, I haven't set up the website in a folder structure, but rather just use this $section tag in each page to denote a section that each page belongs to.

Is there an equivalent options in navigation?

Or perhaps, is there a way I can pass php variables into templates with something like perch_content_custom? Or....would you recommend I restructure and place everything into folders...

Sorry for so many questions, loving the system but a few things I need to learn.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can pass things into the template with PerchSystem::set_var() but it looks like everything you're doing there could just be done automatically with the navigation functions.

The $section part would an an ancestor. You can also test for subitems to see if there is subnav.

Drew McLellan said:

You can pass things into the template with PerchSystem::set_var() but it looks like everything you're doing there could just be done automatically with the navigation functions.

The $section part would an an ancestor. You can also test for subitems to see if there is subnav.

HI Dean,

Thanks again for getting back to me. Ok I think I'm getting it, one last thing I'm not quite sure of though, what exactly constitutes a parent page? I'm just thinking structurally what does ancestor page actually mean? Does the ancestor page have to be a physical .php page sitting inside the sections folder i.e. /about/index.php? With all the child pages in the same folder /about/page1.php /about/page2.php ?

Drew McLellan

Drew McLellan 2638 points
Perch Support

These are parents and ancestors based on the navigation structure created in the Pages section of the control panel. The default state of that is taken from your file structure, but that can change when you use the Reorder page to change that.

So it's whatever hierarchy you see under Pages.

Drew McLellan said:

These are parents and ancestors based on the navigation structure created in the Pages section of the control panel. The default state of that is taken from your file structure, but that can change when you use the Reorder page to change that.

So it's whatever hierarchy you see under Pages.

Thanks so much Drew =) I'll give this a go and let you know

Drew McLellan said:

These are parents and ancestors based on the navigation structure created in the Pages section of the control panel. The default state of that is taken from your file structure, but that can change when you use the Reorder page to change that.

So it's whatever hierarchy you see under Pages.

Hey Drew :) Just wanted to say managed to get it working! Thanks for your help, think it was just the learning curve of getting a handle of the variables that coul dbe used.

Just one question, got the navigation looking as I'd like barring one thing, example below

<li><a href="">Link 1</a>
<ul>
      <li><a href="">Link 2</a></li>
      <li><a href="">Link 3</a></li>
      <li><a href="">Link 4</a></li>
</ul>
</li>

Basically, I would like the subnav to also include the parent item 'link 1', instead of starting from link 2, is there a way to do this?

I do have the include-parent set to true but not sure if this is whta I need here :

<?php
    perch_pages_navigation(array(
        'from-path'  => '*',
        'from-level' => 0,
        'template' => array('nav1.html', 'nav2.html'),
        'include-parent'  => true,
    ));
?>

Many thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does your nav1.html template look like?

Drew McLellan said:

What does your nav1.html template look like?

Here's nav1 :


<perch:before> <ul id="menu"> </perch:before> <li <perch:if exists="current_page"> class="selected"</perch:if><perch:if exists="ancestor_page"> class="ancestor"</perch:if><perch:if exists="subitems"><perch:else /> class="noSub"</perch:if>> <a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a> <perch:pages id="subitems" encode="false" /> </li> <perch:after> </ul> </perch:after>

EDIT : just realised they are nearly identical so tidied this up and just using nav1.html, but still would love some help on how to include the parent link.

Thank you

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure you can once you've stepped down to the subitems.

Drew McLellan said:

I'm not sure you can once you've stepped down to the subitems.

Oh that's a shame =( Is there anyway to duplicate a page then as a child? I'm not sure how to restructure this. See below, I really need the Our Assets to be a sublink, appreciate any suggestions here.

My pages

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think you'd need to add the page twice in order to get it into the navigation twice.