Forum

Thread tagged as: Problem, Members

Members Conditional in Navigation

Hi,

I am trying to use a Members conditional based on tag as part of my navigation template, and it is displaying both parts of the conditional regardless of login. My code is just lifted from the docs at this stage:

<perch:member has-tag="trade">
    <p>TRADE LOGIN</p>
<perch:else:member />
    <p>NON TRADE LOGIN</p>
</perch:member>

The navigation is being called on the page like this:

    perch_pages_navigation([
        'levels'=>2,
        'template'=>['dropdown-refill-level1.html', 'dropdown-refill-level2.html']
    ]);

The template code is in dropdown-refill-level1.html. I am thinking it might be an issue with using these tags in perch_pages_navigation?

Diagnostics report:

Perch Runway: 2.8.24, PHP: 5.6.10, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.24), assets (2.8.24), categories (2.8.24), perch_forms (1.8.3), perch_mailchimp (2.0.1), perch_shop_orders (1.0), perch_shop_products (1.0), perch_shop (1.0g11), perch_members (1.4.3)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_members', 'perch_shop', 'perch_mailchimp' );
PERCH_LOGINPATH: /admin
PERCH_PATH: /Volumes/Data/g Websites/New Development/Newgate/Clocks Build 4 - gamma/admin
PERCH_CORE: /Volumes/Data/g Websites/New Development/Newgate/Clocks Build 4 - gamma/admin/core
PERCH_RESFILEPATH: /Volumes/Data/g Websites/New Development/Newgate/Clocks Build 4 - gamma/admin/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: dc1fef2ad0fcd9f943c02ebb43d85dbc
Resource folder writeable: Yes
HTTP_HOST: newgateclocks.dev
DOCUMENT_ROOT: /Volumes/Data/g Websites/New Development/Newgate/Clocks Build 4 - gamma
REQUEST_URI: /admin/core/settings/diagnostics/
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php

Thanks for your help

Mike Harrison

Mike Harrison 37 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Should be an issue - what result are you getting?

I am seeing both parts of the conditional, regardless of login. The HTML source is outputting the perch tags too:

<perch:member has-tag="trade">
    <p>TRADE LOGIN</p>
<perch:else:member />
    <p>NON TRADE LOGIN</p>
</perch:member>

My complete template is:

<perch:before>
   <div class="centered-navigation" role="banner">
  <div class="centered-navigation-wrapper">
   <div class="menuholder">
    <a href="javascript:void(0)" id="js-centered-navigation-mobile-menu" class="centered-navigation-mobile-menu">Menu</a>
    </div>
    <nav>
    <ul id="js-centered-navigation-menu" class="centered-navigation-menu show">
</perch:before>
        <li class="<perch:if exists="subitems">more</perch:if><perch:if exists="current_page"> selected</perch:if><perch:if exists="ancestor_page"> ancestor</perch:if> nav-link">
            <a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a>
            <perch:pages id="subitems" encode="false" />
        </li>
<perch:after>

      <li class="nav-link"><a href="https://www.newgatewatches.com" target="_blank">Watches</a></li>

</ul>
</nav>
  </div>
</div>

<perch:member has-tag="trade">
    <p>TRADE LOGIN</p>
<perch:else:member />
    <p>NON TRADE LOGIN</p>
</perch:member>

</perch:after>

Ultimately I am looking at swapping the href of the Watches link depending on whether a Trade customer is logged in

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, I'll take a look.

Normally you'd do that by setting the permissions at the page level, but this should work too.

Cheers Drew,

Page level works, but would be more straightforward to edit one navigation template than all my page templates.

Thanks for your help

Hi guys, I'm just doing a simple log-in form and straight form the login_form.html template; I'm also getting both conditionals, i.e. this always displays, even when logged-out

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

    <p>Hi <perch:member id="first_name" />, you are logged in</p>

Was there a fix for this

Im also getting the same issue with login and logout buttons in my navigation

<perch:member logged-in="true">
                <li>
                    <a href="/account/logout" class="hollow button small">Logout</a>
                </li>
                <li>
                    <a href="/account" class="hollow button small">Account</a>
                </li>
                <perch:else:member />
                <li>
                    <a href="/account/login" class="hollow button small">Login</a>
                </li>
                <li>
                    <a href="/account/register" class="hollow button small">Get Started</a>
                </li>
                </perch:member>

Hi, I can't see in the Perch code where the Navigation template is parsed by the membership plugin. I use the workround below in a layout. It isn't ideal as it hardcodes the position of the login/logout link & page details but it works for me.

            <?php
            $navinfo = perch_pages_navigation(array(
                'from-path'            => '/',
                'levels'               => 1,
                'skip-template'        => true), true);

            for( $i = 0; $i < count($navinfo); $i++ ) {
                echo "<li><a href='".$navinfo[$i]['pagePath']."'>".$navinfo[$i]['pageNavText']."</a></li>";
            }
            if (perch_member_logged_in()) {
                echo "<li><a href='logout.php'>Logout</a></li>";
            } else {
                echo "<li><a href='login.php'>Login</a></li>";
            }

            ?>