0

I have page where the content depends on whether you are logged in or not. This is the tag that I used to check

{if logged_out}
   ...
{if:else}
  ...
{/if} 

However, even if I am logged out, I always get to the second part which is meant for logged in users.

I have cleared the cache from EE and the cookies from my browser. But it did not help.

Which parts of EE should I be looking for to solve this problem?

Some more information

  • I am using the url below to log out

    {redirect="?ACT=16&return=/sign-out/"}

  • I am using Safecracker Registration. All the kinks with upgrading to 2.7.1 have been worked out.

UPDATE:

I outputted some variables and I got this

logged_in_member_id: 1
logged_in_group_id: 1
logged_in_group_description:
logged_in_username:
logged_in_screen_name:
logged_in_email: 

Another UPDATE:

I have Template A and Template B.

Template A embeds Template B.

I added code to show logged_in status in both Templates

<div>
    {if logged_in}
        LOGGED IN
    {/if}

    {if logged_out}
        LOGGED OUT
    {/if}
</div>

The problem is that in Template A, logged_in is FALSE

but in Template B, logged_in is TRUE

This is weird. So {logged_in} can be changed?

1

Try:

{redirect="{site_url}?ACT=16&return=/sign-out/"}

The & will probably be treated as part of the string instead of the divider between query strings.

Also try (just to keep it simple):

{redirect="{site_url}?ACT=16"}

Assuming the logout is working and it's the conditional that's at fault, try this conditional instead:

{if logged_out}
   ...
{/if}
{if logged_in}
  ...
{/if}
| improve this answer | |
  • The redirect is a great option, but I would also make the redirect create a login. You could also make the content secure and hidden if member_group == whatever the membergroup needs to be. That works good to. – Cam Oct 7 '13 at 15:22
  • I tried the conditional but they still always evalute to logged_in – developarvin Oct 14 '13 at 4:20
  • No {logged_in} can't be changed between embeds, so if that's occurring, something else is incorrect - you'd need to provide your full template code for the template that is incorrectly reporting logged in (or out). Also have you tried access Template B directly (without going through Template A)? – Peter Lewis Oct 14 '13 at 8:23
0

It's rather strange you're getting different results on different templates.

The overall problem though must have something to do with the parse order, since the {if:else} advanced conditional never really worked for me in EE when applied to a logged_in conditional. You have to consider that an "advanced" conditional is evaluated much later in the parsing order, so it might apply to your situation if it's included inside some {exp} tags.

What version do you have installed? I read that some new parsing rules have been introduced with the latest EE releases. If you have the possibility to update I would do so, otherwise I would stick with:

{if logged_out}
   //DO SOMETHING
{/if}
{if logged_in}
  //DO SOMETHING ELSE
{/if}

You can also give a try to this module: http://devot-ee.com/add-ons/switchee or this one: https://github.com/croxton/ifElse I haven't tested them yet, but apparently they make the advanced conditionals parse earlier in EE templates. Share the results if you happen to try that.

| improve this answer | |
  • Thanks for the response. I am using EE 2.7.2. Btw, if you look at my example above, I did not use {if:else} since I too have problems with it in the past. – developarvin Oct 16 '13 at 13:40
  • It can't return two different statuses in two different templates. Can you post more of your code from the templates? – Milksamsa Oct 16 '13 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.