All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Early parsed Low Variables and CE Cache Problem

JimmyFurtado 26 Apr 2012 13:21 question, complete

I am trying to reduce server load using Early Parsed Low Variables (EPLV) and CE Cache. To avoid the unneeded parsing within the standard if_logged_in/if_logged_out, I am using an EPLV if statement. I use an early escape from CE Cache to avoid having the conditionals cached. Here is my code:

 
<div class="topheader npcontainer">
<div class="row">
<div class="sixteencol">
<div class="topheaderbox">
<div class="headerlogobox">
{sn_nav_subscription}
</div>
<div class="headerloginbox">
{exp:ce_cache:escape:toplog}
{if logged_in_member_id == '0'}
<a href="{path=members/login}">Login</a> | <a href="{path=forums/member/register}">Register</a>
{/if}
{if logged_in_member_id > 0}
<a href="{path=forums/member/profile}">{username}</a> | <a href="{path=LOGOUT}">Logout</a>
{/if}
{/exp:ce_cache:escape:toplog}
</div>
</div>
</div>
</div>
</div>

 
The problem that I am getting is: if a member is logged out, he only sees the appropriate content. Checking the cached data I find:

<div class="headerloginbox">

<a href="{path=members/login}">Login</a> | <a href="{path=forums/member/register}">Register</a>

{if logged_in_member_id > 0}
<a href="{path=forums/member/profile}">{username}</a> | <a href="{path=LOGOUT}">Logout</a>
{/if}

</div>

As you can see, the stuff within the {if logged_in_member_id == '0'} statement gets parsed because during the early parsing, the conditional is true, so everything within the pair gets parsed *and* CE Cache caches the parsed conditional. The logged_in conditional fails and remains because it is escaped. When a logged in person accesses the page he sees *both* the logged_out and logged_in material.

When a logged_in member hits the page first, here is the cache:
 
<div class="headerloginbox">

{if logged_in_member_id > 0}
<a href="{path=forums/member/profile}">{username}</a> | <a href="{path=LOGOUT}">Logout</a>
{/if}

</div>

The logged_in conditional appears but the logged_out doesn't, so when a logged_out person hits the page, he sees nothing.

I know I'm missing something with the parse order. Can you suggest a way I can avoid the parsing of the opposite logged in status that works for both conditions without resorting to imbeds?

Thanks in advance.

Replies

  1. Low 26 Apr 2012 15:04

    Phew! Well, I haven't used CE Cache yet, so I can't say anything about that. But I can say this:

    {if logged_out} is an advanced conditional, so parsed after the tags;
    It's slightly safer to use {if logged_in_member_id == '0'} and {if logged_in_member_id != '0'} (both with quotes) to check for logged in/logged out status. I've seen cases where using > 0 didn't work as expected.

    Either way, if it persists, the also ask the CE people for help, as the conditionals would work without those tags.