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?

  • 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. – Robson Sobral Dec 2 '13 at 11:57
  • If one of them has content, like the IF statement says – Kenny Bones Dec 2 '13 at 13:02
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.

| improve this answer | |
  • 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? – Kenny Bones Dec 2 '13 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). – Bjørn Børresen Dec 3 '13 at 7:36

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.