Forum

Thread tagged as: Question, Problem

Navigation Template Issues

Hi have had a template that worked great when all my pages had sub pages under them.

I now need to have a home button on the menu and it will not work correctly. I am going spare trying to figure it out.

My code in the navigation template is this :

<perch:before>
<perch:if id="pageDepth" match="gt" value="1">
    <ul class="dropdown-menu" role="menu">
<perch:else />
    <ul class="nav navbar-nav">
</perch:if>
</perch:before>
<perch:if id="pageDepth" match="gt" value="1"><li><perch:else /><li class="dropdown"></perch:if><a href="     
<perch:pages id="pagePath" />" <perch:if id="pageDepth" match="gt" value="1"> <perch:else />data-toggle="dropdown" class="dropdown-toggle" </perch:if> ><perch:pages id="pageNavText" /></a><perch:pages id="subitems" encode="false" /></li>
<perch:after>
</ul>
</perch:after>

and the output from this template is this:

<ul class="nav navbar-nav">
<li class="dropdown"><a href="/" data-toggle="dropdown" class="dropdown-toggle"  >Home</a></li>
<li class="dropdown"><a href="/whats-on" data-toggle="dropdown" class="dropdown-toggle"  >What's On</a>
    <ul class="dropdown-menu" role="menu">
        <li><a href="/alpha.php"   >Alpha</a></li>
        <li><a href="/calendar.php"   >Calendar</a></li>
        <li><a href="/children.php"   >Children</a></li>
        <li><a href="/services.php"   >Services</a></li>
        <li><a href="/small-groups.php"   >Small Groups</a></li>
        <li><a href="/students.php"   >Students</a></li>
        <li><a href="/youth.php"   >Youth</a></li>
    </ul>
</li>
<li class="dropdown"><a href="/how-can-we-help" data-toggle="dropdown" class="dropdown-toggle"  >How Can We Help?</a>
    <ul class="dropdown-menu" role="menu">
        <li><a href="/city-centre-chaplain.php"   >City Centre Chaplain</a></li>
        <li><a href="/family-life-centre.php"   >Counselling</a></li>
        <li><a href="/marriage-courses.php"   >Marriage Courses</a></li>
        <li><a href="/pastoral-care.php"   >Pastoral Care</a></li>
        <li><a href="/prayer-support.php"   >Prayer Support</a></li>
        <li><a href="/social-and-ethical-issues.php"   >Social and Ethical Issues</a></li>
    </ul>
</li>

I think I just need to remove :

class="dropdown"><a href="/" data-toggle="dropdown" class="dropdown-toggle"  

When it is only 1 single menu item with no sub pages.

Does any anyone have any ideas?

Thanks.

Phil

Philip Young

Philip Young 0 points

  • 6 years ago

Just to clarify, everything in the above code works as it should.

I just need it tweaked so that the link to 'Home' does not have the class & data toggles.

class="dropdown"><a href="/" data-toggle="dropdown" class="dropdown-toggle"

It should look like:

<li><a href="/">Home</a></li>
Drew McLellan

Drew McLellan 2638 points
Perch Support

How about just testing for it?

<perch:if id="pagePath" value="/">
... this is the home page ...
</perch:if>

Thanks Drew. I have made some progress but can't get it just right.

With the following code I get the home page link working as it should ....

<perch:before>
    <perch:if id="pageDepth" match="gt" value="1">
        <ul class="dropdown-menu" role="menu">
    <perch:else />
        <ul class="nav navbar-nav">
    </perch:if>
</perch:before>
    <perch:if id="pagePath" value="/"><li><a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" />    </a></li>

    <perch:else /><li class="dropdown"><a href="<perch:pages id="pagePath" />" data-toggle="dropdown" class="dropdown-toggle"><perch:pages id="pageNavText" /></a><perch:pages id="subitems" encode="false" /></li>    </perch:if>
<perch:after>
    </ul>
</perch:after>

But the sub navigation inherits a lot of code - <li class="dropdown"><a href="/alpha.php" data-toggle="dropdown" class="dropdown-toggle">Alpha</a></li>

My output is now this:

<ul class="nav navbar-nav">
    <li><a href="/">Home</a></li>
    <li class="dropdown"><a href="/whats-on" data-toggle="dropdown" class="dropdown-toggle">What's On</a>
    <ul class="dropdown-menu" role="menu">
        <li class="dropdown"><a href="/alpha.php" data-toggle="dropdown" class="dropdown-toggle">Alpha</a></li>
        <li class="dropdown"><a href="/calendar.php" data-toggle="dropdown" class="dropdown-toggle">Calendar</a></li>
        <li class="dropdown"><a href="/children.php" data-toggle="dropdown" class="dropdown-toggle">Children</a></li>
        <li class="dropdown"><a href="/services.php" data-toggle="dropdown" class="dropdown-toggle">Services</a></li>
        <li class="dropdown"><a href="/small-groups.php" data-toggle="dropdown" class="dropdown-toggle">Small Groups</a></li>
        <li class="dropdown"><a href="/students.php" data-toggle="dropdown" class="dropdown-toggle">Students</a></li>
        <li class="dropdown"><a href="/youth.php" data-toggle="dropdown" class="dropdown-toggle">Youth</a></li>
    </ul>
    </li>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What should it be like?

The output should look like :

<ul class="nav navbar-nav">
<li><a href="/" >Home</a></li>
<li class="dropdown"><a href="/whats-on" data-toggle="dropdown" class="dropdown-toggle"  >What's On</a>
    <ul class="dropdown-menu" role="menu">
        <li><a href="/alpha.php"   >Alpha</a></li>
        <li><a href="/calendar.php"   >Calendar</a></li>
        <li><a href="/children.php"   >Children</a></li>
        <li><a href="/services.php"   >Services</a></li>
        <li><a href="/small-groups.php"   >Small Groups</a></li>
        <li><a href="/students.php"   >Students</a></li>
        <li><a href="/youth.php"   >Youth</a></li>
    </ul>
</li>
<li class="dropdown"><a href="/how-can-we-help" data-toggle="dropdown" class="dropdown-toggle"  >How Can We Help?</a>
    <ul class="dropdown-menu" role="menu">
        <li><a href="/city-centre-chaplain.php"   >City Centre Chaplain</a></li>
        <li><a href="/family-life-centre.php"   >Counselling</a></li>
        <li><a href="/marriage-courses.php"   >Marriage Courses</a></li>
        <li><a href="/pastoral-care.php"   >Pastoral Care</a></li>
        <li><a href="/prayer-support.php"   >Prayer Support</a></li>
        <li><a href="/social-and-ethical-issues.php"   >Social and Ethical Issues</a></li>
    </ul>
</li>
Drew McLellan

Drew McLellan 2638 points
Perch Support

You're adding those attributes yourself:

<li class="dropdown"><a href="<perch:pages id="pagePath" />" data-toggle="dropdown" class="dropdown-toggle">

Yes. Those attributes need to be added to the parent pages. They should not be added to the submenu items.

Thats what I can't figure out.

I only want those attributes to be added to the parent pages, and only if they have submenu items, but not to the submenu items.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can also test for pageDepth - it increases for each level you go down.

But is the Home Link and the other Parent links not on the same depth?

If they are, I can't differentiate between them which I need to do.

The Home Page link is just a simple link, and the Parent pages are not, they just contain the submenu items.

Or could I put all pages as subpages of Home?

Is there something like:

If a page has child pages 'do this', otherwise ' do that' ?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Sure:

<perch:if exists="subitems">
    ... has sub items ....
<perch:else />
    ... doesn't have sub items ...
</perch:if>

Drew you are a genius.

Thanks!

I on the other hand, really need to go and learn some PHP!