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.

Using global conditionals (logged_in) in entries tag

April 23, 2013 10:44am

Subscribe [1]
  • #1 / Apr 23, 2013 10:44am

    Castlegate IT

    25 posts

    {if logged_in} and {if logged_out} are parsed early, right?

    So why doesn’t this work?

    {exp:channel:entries 
        status="open" 
        channel="pages" 
    {if logged_out}search:public_content="=Yes"{/if}
        dynamic="no" 
    }
        {entry_id}:{title};
    {/exp:channel:entries}

    - where public_content is the short name of a checkbox channel field which has the value ‘Yes’ if checked (and is set searchable in the channel field admin).

    If I take out the {if logged_out}{/if} tags it’s OK & only returns pages marked public_content.

    I’m using EE2.5.2.

    Any ideas?

  • #2 / Apr 25, 2013 10:30am

    Castlegate IT

    25 posts

    Did some further research. People have said “conditional statements inside tag declarations should never be used” - and I finally found an explanation

    I thought if logged_in was always a simple conditional because I thought if logged_in, if logged_out, and member_group were early parsed global variables. What I found, thanks to an observation by Nicolas Bottari from Solspace, is they only operate as simple conditionals within the channel:entries tag.

    - posted by Jim F here

    ...an undocumented feature?

    The first rule of EE seems to be: if in doubt, wrap it in another template. The equivalent of ‘turn it off and turn it on again’.

    So here’s my solution:

    {embed="my-subtemplate" logged_in="{if logged_out}=Yes{/if}"}

    ...
    then in the subtemplate
    ...

    {exp:channel:entries 
        status="open" 
        channel="pages" 
        search:public_content="{embed:logged_in}"
        dynamic="no" 
    }
        {entry_id}:{title};
    {/exp:channel:entries}

    - suits me as I’m trying to pull out public pages for a subnav. Would be keen to hear anyone else’s.

     

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

ExpressionEngine News!

#eecms, #events, #releases