Forum
How to use conditionals with categories in a page template?
Hi,
I'm trying to use the categories field to show html content based on the selected category. Using the docs I have the following code but none of the conditionals seem to be working.
I think that I have the id wrong for categories, can anyone suggest where I'm going wrong please?
<perch:categories id="tan-type" label="Tan Type" set="tanning-types" order="4" />
<perch:if id="tan-type" value="light">
<i class="badge light"> </i>
<perch:elseif id="tan-type" value="medium" />
<i class="badge light"> </i><i class="badge medium"> </i>
<perch:elseif id="tan-type" value="dark" />
<i class="badge light"> </i><i class="badge medium"> </i><i class="badge dark"> </i>
<perch:elseif id="tan-type" value="extra-dark" />
<i class="badge light"> </i><i class="badge medium"> </i><i class="badge dark"> </i><span class="primary-highlight">+</span>
</perch:if>
In your if conditionals your missing match="eq" which could be why is failing... Though I think "eq" is assumed by default, ... This is an untested obsurvation though.
Is there actually a perch:elseif tag? I know of perch:else tag... I did a quick search in the documentation and did not find any results for elseif.
There is no
perch:elseif
tag. Even I had to check that one.I've updated the code to only have if statetements and wrapped my conditionals in the <perch:categories> tag, this now writes out the category title. However my conditionals no longer work, any suggestions?
Updated code:
Are light, medium, dark etc your categories? If so:
Yes they are the categories, thanks for your help.