0

I am trying to control what is displayed in a table view based on a conditional.

Here is the code I am trying to use:

<tr class="odd">
    <td>Small</td>
    <td>1000x600</td>
    <td>$25</td>
</tr>
<tr class="even">
    <td>Medium</td>
    <td>2000 x 1300</td>
    <td>$50</td>
</tr>
{if max_dimensions != '1536 x 2048' OR max_dimensions != '2048 x 1536' }
<tr class="odd">
    <td>Large</td>
    <td>3000 x 2003</td>
    <td>$75</td>
</tr>
{/if}

In this case if the max_dimensions of a photograph is not '1536 x 2048' or '2048 x 1536' I want the third row of data to be displayed.

I limited it to just one conditional as follows and it worked. However when I add the OR, it fails.

{if max_dimensions != '1536 x 2048' }
<tr class="odd">
    <td>Large</td>
    <td>3000 x 2003</td>
    <td>$75</td>
</tr>
{/if}

That basic objective is, if the picture is not big enough, I don't want the third row to be displayed. What is the correct way to word this?

Thanks.

1

You can't really use an OR conditional when both are "not equal to" because both conditions can be satisfied at the same time (as in your example, when the entry in question matches both conditions at the same time). You can easily use OR when you are asked for equal to, but not equal to is a different animal. On the surface it seems like OR is what you're looking for, but really what it seems you're looking for is this:

{if max_dimensions != "option A" OR "option B"}
    display third row only if max dimensions are anything other than options A or B
{/if}

But that's not how such a conditional is written - but that's the structure of the logic you are going for. But to write that, you use:

{if max_dimensions != "option A" AND max_dimensions != "option B"}
    display third row only if max dimensions are anything other than options A or B
{/if}

By using AND you are saying you want the third row to display whenever options A and B are not the value. By using OR, you're saying you want the third row if option A is not the value or option B is not the value - two conditions rather than one, which buggers up the logic a bit.

Make sense?

| improve this answer | |
  • Hi Jean, yes, this is exactly what I needed. I knew there was a logic point there and this is it. Thank you. – forrest Apr 26 '13 at 17:04
  • You're very welcome! – Jean St-Amand Apr 26 '13 at 19:26
0

Can you try it:

{if "{max_dimensions}" != "1536 x 2048" OR "{max_dimensions}" != "2048 x 1536"}
<tr class="odd">
    <td>Large</td>
    <td>3000 x 2003</td>
    <td>$75</td>
</tr>
{/if}

If it didn't work, you can try another quick way:

    {if "{max_dimensions}" != "1536 x 2048"}
    <tr class="odd">
        <td>Large</td>
        <td>3000 x 2003</td>
        <td>$75</td>
    </tr>
    {if:elseif "{max_dimensions}" != "2048 x 1536"}
    <tr class="odd">
        <td>Large</td>
        <td>3000 x 2003</td>
        <td>$75</td>
    </tr>
{if:else} {/if}
| improve this answer | |
  • Hi Bhashkar, I tried it and it still does not work correctly. If I remove the OR option it does work, so we are close. – forrest Apr 25 '13 at 18:27
  • interesting... just updated my answer with another quick solution. You can try it. – Bhashkar Yadav Apr 25 '13 at 18:33
  • I considered that as well, but either way, it will show the row. We really need the OR option to work. – forrest Apr 25 '13 at 18:37
  • I couldn't understand why second option isn't working without OR condition. I think, it would work same as your OR condition. as OR condition will have logic: TRUE OR False = True, False OR True = True, True OR True = True, False OR False = False. Same thing would happen with if:elseif condition. – Bhashkar Yadav Apr 25 '13 at 18:45
  • I don't understand either. I tried it and it didn't work. – forrest Apr 25 '13 at 18:56

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.