Forum
perch:if and categories
I'm trying but failing to display differing shop product template content dependent on product category. I'm wanting to display either a 'buy' or 'register' button depending on whether the product is physical or an event.
In semi-psuedo code, I'd envisaged something like this working:
<perch:if match="category" value="products/physical">
<perch:input type="submit" value="Buy" />
</perch:if>
<perch:if match="category" value="products/event">
<perch:input type="submit" value="Register" />
</perch:if>
… but think I'm mixing up id and category filtering and so getting nowhere.
Ta.
Replying to myself, but thinking about it, my suggestion would be a bad way to achieve what I want (hardcoding a template against an externally set variable), so think it makes more sense to hardcode the pre-determined product types into the product template itself …
… and then filter on that ID.
Or even just check that an ID that only the events have (i.e. a date) exists, and run the
<perch:if
on that.If you're using
<perch:if ...
, thematch
tag should beeq
orgt
orlt
etc - so that's why it's failing. It should beThe id probably won't be "category", it's probably
catPath
.I considered that Duncan, but a category doesn't perform as a regular id does, does it? i.e., there's nothing in
<perch:showall />
that gives the category value itself to match on, just the array of category IDs.Categories have always confused me …
You need to use categories tags to loop through the categories:
Thanks as ever, Drew.
For the record, I needed to include a trailing slash on the value to get that working: