3

I've got

{if segment_3 == "desc" OR segment_4 == "desc"}

and EE is just ignoring it or not parsing it or something. I can try

{if segment_3 == "desc" || segment_4 == "desc"}

and that doesn't work either. However, if i have {if segment_3 == "desc"} on it's own, that works fine.

What's going on here huh?

More of the code around this, it's in a channel:entries tag and it's to define whether a orderby and sort paramater is applied:

{exp:channel:entries
channel="my_channel"
limit="15"
paginate="bottom"
{if segment_3 != "asc" OR segment_4 != "desc"} category={segment_3_category_id} {/if}
{if segment_3 == "desc" || segment_4 == "desc"} orderby="woa-price" sort="desc"{/if}
{/channel:entries}
  • There's more going on here - what are you doing within this conditional block which is telling you that it's not working? Can you post the code in context? – Derek Hogue Dec 18 '12 at 16:14
  • @DerekHogue There you go Derek, see above edit to original questions. Cheers for looking at this :) – JohnWBaxter Dec 18 '12 at 16:28
5

This is a parse order issue. The advanced conditional gets parsed after the channel entries tag. Try something like this:

{exp:channel:entries
channel="my_channel"
limit="15"
paginate="bottom"
category="{if segment_3 != "asc"}{segment_3_category_id}{/if}{if segment_4 != "desc"}{segment_3_category_id}{/if}"
orderby="{if segment_3 == "desc"}woa-price{/if}{if segment_4 == "desc"}woa-price{/if}"
sort="{if segment_3 == "desc"}desc{/if}{if segment_4 == "desc"}desc{/if}"
{/channel:entries}

Not sure if those conditions will match the URLs that you've got setup, but that is how you will have to do it. You need to use simple conditionals inside of the channel entries parameters.

| improve this answer | |
  • Rats, i was trying to avoid that to keep the code a bit leaner. Oddly, the first advanced conditional works ok. Cheers!! – JohnWBaxter Dec 18 '12 at 16:53
4

You're running into a parse order issue here. This is because when you have multiple comparison operators in a conditional, that's an advanced conditional. Advanced conditionals are parsed after module tags (like channel:entries).

This solution might work for you though - use preload_replace variables:

{if segment_3 == 'desc'}
    {preload_replace:orderby="woa-price"}
    {preload_replace:sort="desc"}
{/if}
{if segment_4 == 'desc'}
    {preload_replace:orderby="woa-price"}
    {preload_replace:sort="desc"}
{/if}
{preload_replace:orderby="date"}
{preload_replace:sort="asc"}

Then you can use orderby="{orderby}" and sort="{sort} in your channel:entries tag.

This should work because these are simple conditionals, so they are parsed early, and because preload_replace variables saved based on their first parsed instance (so if your conditionals are met, the later declarations that are outside of the conditionals are ignored).

| improve this answer | |
  • I went with the answer below in the end, but thanks for your help and input!! – JohnWBaxter Dec 18 '12 at 18:49
1

It may be treating the simple conditional and the complex conditional differently. Maybe try:

{if '{segment_3}' == "desc" OR '{segment_4}' == "desc"}

See if that then parses.

| improve this answer | |
  • Nope, same problem! I'm sure i've had this issue before and fixed it with something similar. Can't remember what now though! – JohnWBaxter Dec 18 '12 at 15:40
  • Try it all with double quotes... {if "{segment_3}" == "desc" OR etc. – foamcow Dec 18 '12 at 16:40
  • Are you using any add-ons that will interfere with the segment setting? – foamcow Dec 18 '12 at 16:41

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.