0

I've got a weird one going on here. EE 2.8 site.

I wanted to create a conditional based on whether it was ME on the site. I wanted to see some info that was not to be rendered to the normal user. So, I tried to create a conditional like:

{if member_id == '1'} show this {/if}

It didn't work on the post of interest (and my member ID is "1"), so I tried the same with username and screen_name. Still didn't work.

So, I started printing out the {username}, {member_id} and {screen_name} and discovered that they match the author of the post (my wife), not me as the logged in user.

Yet, elsewhere on the site the {screen_name} variable works because I show the name of the currently logged on user.

Does anyone have any idea why these global variables would take on the value of the author (and all three reflect the author whether it is me or my wife), instead of the logged in user?

1

That's normal behaviour but can be a little confusing the first time you encounter it. You need to use {logged_in_username}, {logged_in_member_id}, and {logged_in_screen_name}.

In order to be able to use some member variables inside tags that already parse their own member information, such as the channel entries tag, it is necessary to use an alternative syntax. All of the member variables may be used with the addition of the prefix “logged_in_”.

Alternate syntax for member variables: https://docs.expressionengine.com/latest/templates/globals/single_variables.html#global-alt-syntax

2
  • Thanks! While I'll try it later today, I assume "logged_in_username" for a non-logged-in person is "Guest"? – Rick Robinson Apr 18 '16 at 11:06
  • 1
    No. {logged_in_username} for a non-logged-in visitor returns no value. (Just tested this myself) – user1365655 Apr 18 '16 at 13:13

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.