ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

if logged_in / logged_out within cached entries tag bug maybe???

October 11, 2011 8:52am

Subscribe [3]
  • #1 / Oct 11, 2011 8:52am

    Neil Evans

    1403 posts

    Hey all,

    i have a login widget displayed in my side column on my website - and due to its location it is within an entries tag. That entries tag is clearly set to cache for performance, but it seems to be caching the logged_in and or logged_out state…

    Surely this is incorrect behaviour or am i doing something very wrong?

    For example, on a sandbox test i have the following:

    {exp:channel:entries channel="test_channel" entry_id="3" limit="1" cache="yes" refresh="45" }
    
    <h3>{title}</h3>
    
    <p>{if logged_in}<br />
        You are already logged in. <a href="http://{path=logout}">LOGOUT</a><br />
    {/if}</p>
    
    <p>{if logged_out}<br />
    {exp:member:login_form return="my/page"}<br />
    <label>Username</label></p>
    
    <p><input type="text" name="username" value="" maxlength="32" class="input" size="25" /></p><br />
    <label>Password</label></p>
    
    <p><input type="password" name="password" value="" maxlength="32" class="input" size="25" /></p><br />
    <input type="submit" name="submit" value="Submit" /></p><br />
    {/exp:member:login_form}<br />
    {/if}</p>
    
    <p>{/exp:channel:entries}

    And this will always show the logged in value, even after i click the logout link - until i update the article, or the template in the control panel (i.e. that forces a clear of cache).

    This is on a EE2.2.2 sandbox, and also occurs on an older 2.1.3 generation site…
    Yes i guess caching turned off for this page solved the problem - but less than ideal!

    N

  • #2 / Oct 11, 2011 12:00pm

    jonathanmelville

    132 posts

    It looks like what you’re trying to do isn’t going to work. You can’t use if logged_in inside of channel:entries that utilize tag caching (or any form of caching, including template caching).

    From the User Docs:

    Note: Use of {if logged_in} and {if logged_out} inside a Channel Entries tag on a cached template will not display properly. The logged in state of the user whose visit prompts the cache to be written will permanently affect the information displayed to all visitors.

  • #3 / Oct 11, 2011 12:17pm

    Neil Evans

    1403 posts

    Agreed, missed that note…
    So it is known limitation, but not really a great one!!! I guess no cache or embeds are the options then.

  • #4 / Oct 11, 2011 12:56pm

    jonathanmelville

    132 posts

    I’m not sure what you’re trying to do, but based on your code something like this might work:

    {if logged_in}
       {exp:channel:entries channel="test_channel" entry_id="3" limit="1" cache="yes" refresh="45" }
       <h3>{title}</h3>
    <p>    You are already logged in. <a href="http://{path=logout}">LOGOUT</a><br />
    {/exp:channel:entries}<br />
    {/if}</p>
    
    <p>{if logged_out}<br />
    {exp:member:login_form return="my/page"}<br />
    <label>Username</label></p>
    
    <p><input type="text" name="username" value="" maxlength="32" class="input" size="25" /></p><br />
    <label>Password</label></p>
    
    <p><input type="password" name="password" value="" maxlength="32" class="input" size="25" /></p><br />
    <input type="submit" name="submit" value="Submit" /></p><br />
    {/exp:member:login_form}<br />
    {/if}

    This removes the {if logged_in} statement from the channel entries tag loop.

     

  • #5 / Oct 11, 2011 2:04pm

    Neil Evans

    1403 posts

    Well… typically i have the how page wrapped in a single entries tag, so i can manage everything from META, through title, content, side column, and footer keywords, etc… So the entire template is effectively wrapped in on big entries tag… and then i just wanted logged_in / logged_out in the header or side column.

    That make sense? Using your example from the above, i would have the code twice / or have to work around that part…
    Yes i could have multiple entries tags - seems inefficient
    Yes i could use embeds - put up with the extra overheads

    Just seems odd that they get cached… especially when other things such as plugins do not!

  • #6 / Oct 11, 2011 2:40pm

    jonathanmelville

    132 posts

    I’m sorry but I don’t follow 😊

    You’re saying that you wrap your entire index template for the front page in a channel:entries tag?

  • #7 / Oct 11, 2011 9:07pm

    Dan Decker

    7338 posts

    Hi all,

    Since the issue has been technically cleared up, and this is now more of a discussion I’m going to move this into Community Help.

    Cheers!

  • #8 / Oct 12, 2011 6:37am

    Neil Evans

    1403 posts

    Hi Jonathan,
    Effectively yes - whether it is the index template, or a specific page, or news template, yes, typically all the HTML within that template is wrapped in a single entries tag.

    This is mainly because i manage everything from header images, meta data, title, content, side-blocks, etc, all from that single “pages channel” using playa or another relationship field to tie in other elements such as the side blocks.
    With the use of snippets for commonly used elements this makes the whole process very efficient, especially on server load (as opposed to multiple entries tags, embeds, etc).

    Does that make sense? N

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases