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.

Global Conditional Variable - What Am I Doing Wrong?

August 26, 2011 12:20am

Subscribe [3]
  • #1 / Aug 26, 2011 12:20am

    Lora

    26 posts

    Hi!

    Sure I’ve done something wrong here, but what, I don’t know.

    I’m trying to show something only if the logged in user is a super admin or the logged in user’s member_id is the same as the member_id to prevent the logged in user from looking at someone else’s page (unless they’re me!).

    {if logged_in_member_id != "{member_id}" OR logged_in_group_id != "1"}

    Please, I beg you, tell me the error of my ways.

  • #2 / Aug 26, 2011 12:24am

    Lora

    26 posts

    Oops.

    I put the deleted one in.

    This is the real one!

    {if logged_in_member_id == "{member_id}" OR logged_in_group_id == "1"}
  • #3 / Aug 26, 2011 12:30am

    Lora

    26 posts

    By the way, I think the trouble is around “{member_id}” because if I set logged_in_member_id to a number (e.g., == “3”) it works fine. Except it defeats the purpose of being a general prescriptive…

    Perhaps I can’t use the global variable within the quotes? If so, where does that leave me?

  • #4 / Aug 26, 2011 1:28am

    Dave @ Exp:resso

    465 posts

    I’m assuming you’re using this inside a channel entries loop? So you can tell if the logged in member is the author of a particular entry? In that case you need to use {author_id}, not member_id.

    If you’re using this on a member profile page it should work, as long as its inside any relevant tags. You could try without the quotes

    Let me know how you get on

  • #5 / Aug 26, 2011 5:00am

    Lora

    26 posts

    Hey Dave.

    Thanks for responding.

    I should have elaborated on the context. No, I’m using it on a member page, and the trick was to put it inside the tag. I used the quotes since I’m using the variable as a value.

    It worked great.

    I thought they were all global variables and that I could put them outside tags. But reading the documentation again (and again, and again), it looks as though the logged_in prefix is usable within the channel tags, etc. and not a global variable?

    Thanks so much for the tip.

  • #6 / Aug 26, 2011 5:04am

    Dave @ Exp:resso

    465 posts

    Glad you got it sussed! Well I’d say the logged_in_member_id is more ‘global’ than ‘member_id’ - since member_id can change depending on context. So we always use the logged_in prefix when getting the id of the logged in member or group.

  • #7 / Aug 26, 2011 12:45pm

    Marcus Neto

    1005 posts

    testwise,

    Do I understand that you have this one working now?

  • #8 / Aug 26, 2011 3:52pm

    Lora

    26 posts

    I do, Marcus. Thank you.

    And thanks, Dave, for the extra info in your last post.

  • #9 / Aug 26, 2011 4:00pm

    Lisa Wess

    20502 posts

    Glad to hear it, testwise!  Have a great weekend, and please let us know if you have any other questions. =)

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

ExpressionEngine News!

#eecms, #events, #releases