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 variables in {exp:weblog:entries} not working

September 08, 2011 5:39pm

Subscribe [2]
  • #1 / Sep 08, 2011 5:39pm

    newvibes

    28 posts

    Hi there,
    I’m moving some articles into an archive section of my site and instead of making duplicate templates I thought I’d add them all to an archive category and assign that category Id to a global variable and then use that global variable in my {exp:weblog:entries} tag like so…

    Global Variable ( {current_year_category} )

    16

    Template

    {exp:weblog:entries weblog="artists" orderby="random" limit="1" dynamic="off" category="{current_year_category}" }

    When I view my template it doesn’t show anything in that section. But if I use the {exp:weblog:entries} tag normally

    {exp:weblog:entries weblog="artists" orderby="random" limit="1" dynamic="off" category="16" }

    ... then I get the entries showing. My global variable only has the id of the category in it and nothing else.

    Any ideas would be really appreciated.

  • #2 / Sep 08, 2011 6:09pm

    Mark Bowen

    12637 posts

    Hi newvibes,

    What you are experiencing here is happening because Global Variables are one of the last items parsed in templates so this is a parse order issue I’m afraid.

    This page here in the documentation explains this a little more.

    What you can use instead though would be a Snippet which should allow you to do what you want here.

    Does that help at all?

    Thanks,

    Mark

  • #3 / Sep 08, 2011 8:42pm

    Mark Bowen

    12637 posts

    Hi newvibes,

    It was just pointed out to me that you are running ExpressionEngine 1.x here and not 2.x

    I had completely misread which forum this post was in and must have had blinkers on my eyes when looking at your code pasted above. Apologies.

    I’ve edited the link in the post above to give you the correct documentation page though.

    Thanks,

    Mark

  • #4 / Sep 09, 2011 4:34pm

    newvibes

    28 posts

    Hi Mark,
    Thanks for the response. I had a look at the documentation and it looks like I need another way to do this.

    Thanks.

  • #5 / Sep 09, 2011 5:15pm

    Mark Bowen

    12637 posts

    Hi newvibes,

    Sorry I meant to link to this earlier on but take a look at the Fresh Variables module. That should allow you to do what you need here.

    Thanks,

    Mark

  • #6 / Sep 09, 2011 5:35pm

    newvibes

    28 posts

    Oh snap! Thanks Mark. That might just do the trick. I’ve actually refactored a lot of my code to use the category segments in urls for now, but I’ll try and implement this later on as it’ll assist me in making the URLs a bit more readable too.

    Thanks again!

  • #7 / Sep 09, 2011 7:08pm

    Mark Bowen

    12637 posts

    Oh snap! Thanks Mark. That might just do the trick. I’ve actually refactored a lot of my code to use the category segments in urls for now, but I’ll try and implement this later on as it’ll assist me in making the URLs a bit more readable too.

    Thanks again!

    No problem. Hope that helps a bit.

    I’m going to go ahead and close this thread now but if you have any more problems then please don’t hesitate to post again as needed.

    Cheers,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases