Forum
implementing an OR statement using
I'm just getting into perch so I may be missing something here but it seems that the conditional logic in perch doesn't lend itself to a DRY approach. For example, there doesn't appear to be a way to do the following (using PHP as example):
if (isset($item1) || isset($item2)) { display content };
The specific example is in the code snippet below. I'm trying to prevent the parent container (.content-block) from appearing unless either the 'shout' content or the 'body' content is populated. I've seen suggestions in the forums that I can use nested if/else statements but that will require repeating code at least once. Is there any way around this?
example:
<perch:if exists="shout" OR "body">
<div class="content">
<perch:if exists="shout">
<h2 class="shout"><perch:content id="shout" type="text" label="Shout heading" /></h2>
</perch:if>
<perch:content id="body" type="textarea" label="Body" markdown="true" editor="markitup" />
</div>
</perch:if>
You've just quoted it incorrectly:
Ah that's interesting. Good to know it is something that exists then :) Oddly it seems to be resolving as true even if neither id has content though.
Am I still doing it wrong in some way?
What does
<perch:showall />
output?Can you confirm you're running the latest version of Perch?
Perch: 2.7.2 downloaded from the site on Tuesday. I assume it's the latest version.
Should be good enough.
All my unit tests are passing for that logic, so it should be fine.
How are you displaying the region? If using
perch_content()
have you re-saved after changing the template?Yeah I'm using perch_content() and I've re-saved. Not sure what's going on then. I'll have to keep digging. I'll let you know if I find anything :)