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.

Use global variable in channel tag?

January 17, 2011 7:11pm

Subscribe [3]
  • #1 / Jan 17, 2011 7:11pm

    leeaston

    634 posts

    Using latest EE version.

    The code below is using the global variable {location} to feed the search parameter, but no entries are being returned. If I substitute {location} with it’s actual value then entries are returned.

    How come the global variable {location} isn’t working, I must be missing something?

    {exp:channel:entries channel="{segment_1}" limit="5" search:postcode="{location}"}
    {title}<br>
    {/exp:channel:entries}

    Thank you
    Lee

  • #2 / Jan 18, 2011 10:37am

    Sue Crocker

    26054 posts

    If you put in {location} before the exp:channel:entries loop, is it returning what you expect?

  • #3 / Jan 18, 2011 10:38am

    leeaston

    634 posts

    Hi Sue, yes it is.

  • #4 / Jan 18, 2011 10:27pm

    Sue Crocker

    26054 posts

    I can replicate the problem you’re having.. but the problem is using the global variable of {location}. If you change that global variable to something else (I used location_stuff) it’ll work.

    Does that help?

  • #5 / Jan 19, 2011 6:28am

    leeaston

    634 posts

    I can replicate the problem you’re having.. but the problem is using the global variable of {location}.

    Is it a bug that needs reporting?

    If you change that global variable to something else (I used location_stuff) it’ll work.

    Yes, but the location global variable (as entered in their profile) can be used anywhere within my templates, and it’s site by the site members when they register.

  • #6 / Jan 19, 2011 5:06pm

    Ingmar

    29245 posts

    Is {location} set by you? Or taken from the user’s profile?

  • #7 / Jan 19, 2011 5:07pm

    leeaston

    634 posts

    Taken from users profile?

  • #8 / Jan 20, 2011 4:36am

    Ingmar

    29245 posts

    You’re probably running into a parse order issue here. What happens when you try using

    $this->EE->session->userdata['location']

    instead, with PHP on Input?

  • #9 / Jan 20, 2011 5:02am

    leeaston

    634 posts

    It’s not a parse order problem, Sue replicated the problem - see post 3 above.

    I created a simple template with just this code and it dosen’t work. Substituting {location} with it’s real value works.

    {exp:channel:entries channel="alsace" limit="5" search:postcode="={location}"}
    <a href="http://{path=">{title}</a><br>
    {/exp:channel:entries}

    The code you gave me (below) echo’s out the correct value for {location} when used stand alone, but when placed in the code (below) it dosent return the correct results.

    {exp:channel:entries channel="alsace" limit="5" 
    search:postcode="=<?php $this->EE->session->userdata['location'] ?>"}
    <a href="http://{path=">{title}</a><br>
    {/exp:channel:entries}
  • #10 / Jan 20, 2011 5:17am

    Ingmar

    29245 posts

    You’ll need to echo out the variable, too, like so:

    <?=$this->EE->session->userdata['location'];?>
    or
    <?php echo $this->EE->session->userdata['location'];?>
  • #11 / Jan 20, 2011 5:23am

    leeaston

    634 posts

    Thanks, that works, but now I have the overhead of PHP on a template.

    How come a very simple template with just this code dosen’t work?

    {exp:channel:entries channel="alsace" limit="5" search:postcode="={location}"}
    {title}<br>
    {/exp:channel:entries}
  • #12 / Jan 20, 2011 5:34am

    Ingmar

    29245 posts

    Because {location}, as a built-in global variable, is parsed long after {exp:channel:entries} has finished doing so.

    Standard and User-Defined Global Variables including {path} and {stylesheet} get parsed after practically everything else, right before output starts.

  • #13 / Jan 20, 2011 5:47am

    leeaston

    634 posts

    Thank you, I’ll remember that 😊

  • #14 / Jan 20, 2011 5:48am

    Ingmar

    29245 posts

    Glad to see that explains it to you. Parse Order is my own personal nemesis as well 😊

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

ExpressionEngine News!

#eecms, #events, #releases