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.

How to match segments and global variables

November 13, 2008 7:17pm

Subscribe [1]
  • #1 / Nov 13, 2008 7:17pm

    Chris Ediger

    46 posts

    I’m attempting to only embed a sub-template if a segment match occurs, but I can’t seem to get it to work correctly. Here’s my code:

    At the top of the template:

    {assign_variable:this_mainabout="aboutwwp"}
    {assign_variable:this_section="wwptour"}

    In the template:

    {if this_mainabout==segment_2}{embed="{this_section}/.include_quotes"}{/if}
  • #2 / Nov 13, 2008 9:11pm

    jayf

    41 posts

    Because EE evaluates different tags at different times, your code isn’t working the way a typical program would, executing from first line to last line.

    Rather (as I understand it), there are a series of substitutions happening on the whole template. So, you can imagine a bunch of searches and replaces across the whole template putting new values in for different types of tags, until it’s transformed to the final output state.

    Here’s a reference to the EE template Parse Order:

    http://expressionengine.com/wiki/Parse_Order/

    In the case of your example, I think what’s happening is that your this_mainabout variable (a “Dynamically Assigned Global Variable”) is being parsed *after* the conditional IF statement (a “URI Segment conditional”). So, the IF isn’t actually comparing what you’d think it should be.

    So, I’d try to handle this by just getting rid of the this_mainabout variable in your IF statement:

    {if "aboutwwp"==segment_2}{embed="{this_section}/.include_quotes"}{/if}


    I’ve built many dozens of EE templates, and I still get tripped up by the Parse Order once in a while. But having handy that Parse Order reference on the EE wiki can really help when you run-up against something like this.

  • #3 / Nov 15, 2008 4:27pm

    Chris Ediger

    46 posts

    Thanks. That helps. I already had the “{if segment_2=="aboutwwp"}” there first, but I was trying to get to a quickly replicatible template where I defined all changing variables first. To that end I wound up setting the variable I wanted to use in that conditional as a PHP value first, had it echo the variable in the conditional and then set the template to parse PHP first. Works fine that way - not as clean, but that’s fine for me for now.

    Thanks for the help & the link. That Parse Order reference is going to be a God-send!

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

ExpressionEngine News!

#eecms, #events, #releases