We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Members

Hide certain navigation items from Perch Members who are logged in

If a member is logged in - is there anyway of hiding certain navigation items from them.

I know that if (perch_member_logged_in()) can be used on certain elements but I'm unsure how to use this type of thing within the navigation template?

Richy Thomas

Richy Thomas 0 points

  • 3 years ago
Simon Clay

Simon Clay 127 points

Untested, but I would think you should be able to wrap your nav items with <perch:member logged-in="true"> in your template. e.g.:

<perch:before>
    <ul>
</perch:before>
    <perch:member logged-in="true">
        <li<perch:if exists="current_page"> class="selected"</perch:if>
            <perch:if exists="ancestor_page"> class="ancestor"</perch:if>>
            <a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a>   
            <perch:pages id="subitems" encode="false" />
        </li>
    </perch:member>
<perch:after>
    </ul>
</perch:after>

But won't this hide all of the navigation items from a logged in member?

Say for example on my Nav I have

Home / About / Registration / Contact

When a user has registered and logged in - I only want them to see

Home / About / Contact

As the registration page is no longer required as they've already filled in this form.

Simon Clay

Simon Clay 127 points

Yes, you are right. Of course! Apologies.

The simplest way I can think of. is to tick 'Hide from main navigation' for the page you want hidden from Logged in Members in Page Options. Then, to display your nav:

 <?php
    if (perch_member_logged_in()) {
         perch_pages_navigation();
    } else {
        perch_pages_navigation(array(
            'include-hidden'       => false,
        ));
    }
 ?>

However, if you've used 'Hide form main navigation' for other purposes, that may cause problems. In that case you could use Navgroups in the same way.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You could use a page attribute along with Simon's first suggestion.

Simon Clay

Simon Clay 127 points

Or, perhaps this: Back to the Nav template. Give the <li> item a class of 'hide' if the url is '/registration/index.php' and the member is logged in. Again, untested.

<perch:before>
    <ul>
</perch:before>

        <li class"<perch:if id="pagePath" value="/registration/index.php"><perch:member logged-in="true">hide</perch:member><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>

then hide .hide with css ?

Is this

 <perch:member logged-in="true">

Correct as this is just outputting this in the html?

I know you can use

if (perch_member_logged_in()) {

but this is a .html page as apposed to a .php page

So my items.html has this:

<li class="<perch:if id="pagePath" value="/learning-community/register"><perch:member logged-in="true">hide</perch:member></perch:if>">

But that is out putting this:

<li class="<perch:member logged-in=" true"="">hide"&gt;
  <a href="/learning-community/register">Join Our Learning Community</a>
</li>
Rachel Andrew

Rachel Andrew 394 points
Perch Support

You need to use Perch template tags in your templates, not in your pages.

Hi Rachel,

Yes I am,

I have this code

<li class="<perch:if id="pagePath" value="/learning-community/register"><perch:member logged-in="true">hide</perch:member></perch:if>">

in perch > templates > navigation > items.html

But it is still outputting like this:

<li class="<perch:member logged-in=" true"="">hide">
<a href="/learning-community/register">Join Our Learning Community</a>
</li>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have the Members app installed?

Yes I do have it installed. I'm just wondering if there's a syntax error there that i'm not seeing perhaps?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like navigation templates aren't parsed for member tags on account of the native integration with Members.

You could pass in a flag:

PerchSystem::set_var('logged_in', perch_member_logged_in());

and then compare that with a page attribute

<perch:if exists="page_requires_login AND logged_in"> ... </perch:if>