Forum

Thread tagged as: Question, Problem

Display only if multiple conditions are met

Can I have a perch:if tag that checks for multiple values? I've got a title that I want to check if 2 values exist and appear only if they both do.

First I tried using <perch:before> on the <ul> and <perch:after> on the </ul> but it's already inside a <ul> that has that, which I guess is why it's not working.

Thanks :)

Martin Underhill

Martin Underhill 5 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can nest perch:if tags.

<perch:if exists="conditionA">
    <perch:if exists="conditionB">
        ... both conditions have been met ...
    </perch:if>
</perch:if>

Perfect! Thanks :)

Actually, can I do something that would be like an 'or', so if item 1 or item 2 exists then display something?

Drew McLellan

Drew McLellan 2638 points
Perch Support

<perch:if exists="conditionA">
    ... output ...
<perch:else />
    <perch:if exists="conditionB">
        ... output ...
    </perch:if>
</perch:if>

And if what you need to output is to big to repeat, put it in a sub template.

Fantastic! I've nested an else there too, so that nothing is returned if neither condition is met:

<perch:if exists="conditionA">
  ... output ...
<perch:else />
  <perch:if exists="conditionB">
    ... output ...
  <perch:else />
  </perch:if>
</perch:if>

Thanks for your help!