Forum
Perch if - test for either of the two exists
Hi,
I want to use Perch if to see if either of these exist, if one or both do then show the content. Using OR seems to only show them if both match which doesn't make sense?
<perch:if exists="case-study-quote OR awards">
...
</perch:if>
That looks like it should work - what does
<perch:showall />
output?case-study-quote always gets outputted with a value or without one awards only seems to if there is one.
awards is a repeater, would this make a difference? The full code:
You can't test for the existence of a repeater - you have to check for the existence of content.
Do you see the repeater values output in
perch:showall
?I get this if there is an award
I have been testing against the repeater (awards) to display its sub section. If I just test against the content (award) it doesn't work
Do you don't get an
awards.award
item?Nope, all I get is the above.
Ok, that's odd. I'm not sure how to help in that case. Is it only the OR that fails?
Just done some testing using other content.
It always works as expected on individual items when I add OR using two content ids that previously worked on their own they no longer do.
Only when they're repeaters?
What I've just been testing aren't content with repeaters.
It works individually, not together with OR
Below example "case-study-quote" does exist "main-heading" does exist "video" doesn't exist
Hello appears:
Hello appears
Hello doesn't appear
Hello doesn't appear
Dashes aren't actually legal in IDs. I wonder if that's a contributing factor.
All my unit tests for this functionality are passing, so there's obviously some subtlety to it.
That's done the trick. I now need to get out of the habit of using dashes. Thanks Drew!