0

I want to check if two tags have content in them, and set html markup accordingly. And I reuse this snippet several places and I'm having inconsistent results.

{if site_hvite_left == "" OR site_hvite_right == ""}
    <div class="row-small">
{if:else}
    <div class="row">
{/if}

Some places this works just fine, but other places, I need to add a space in between the quotes for it to make it work. Which makes me think there might be a better way of doing this. Any ideas?

2
  • If both fields have content or one of them? Please, update your question and give us more details. Maybe, the :empty pseudo-class can help you too.
    – Sobral
    Dec 2, 2013 at 11:57
  • If one of them has content, like the IF statement says Dec 2, 2013 at 13:02

1 Answer 1

1

Try this:

{if '{site_hvite_left}' == '' OR '{site_hvite_right}' == ''}
    <div class="row-small">
{if:else}
    <div class="row">
{/if}

.. a bit verbose but it should work every time.

2
  • Actually, it was the single quotes that made it work. But out of curiosity, what makes the '{site_hvite_left}' tag differ from 'site_hvite_left' without brackets? Dec 2, 2013 at 13:03
  • 2
    Well, what makes single quotes differ from double? The EE template parser works in mysterious ways. It's a regexp search-and-replace solution, so my logic with the above is that {site_hvite_left} etc. will be replaced with content first if they have brackets. Turns out it was the quotes in this case, but the above is still what I have found to work in most cases. And btw - nobody really knows how this parser works in all situations (even EllisLab support will just tell you to try different solutions until you hit one that works). Dec 3, 2013 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.