Forum

Thread tagged as: Question

perch:if & categories

Wondering if there is a way to use Perch for some logic with categories.

<perch:categories id="categories" set="blog" />
     // If there are multiple categories & this is not the first
        extra notation <perch:category id="catTitle" />
    // else
        <perch:category id="catTitle" />
</perch:categories>
Nicholas Nelson

Nicholas Nelson 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can test for perch_item_first

Cool. Alright correct me if I'm wrong here... I'm looking to output something like:

CatTitle1 - CatTitle2

I have this code:

<perch:categories id="categories" set="blog" />
    <perch:if id="perch_item_first">
        <perch:category id="catTitle" />
    <perch:else />
        - <perch:category id="catTitle" />
    </perch:if>
</perch:categories>

Which is outputting:

- CatTitle1 CatTitle2

Does this seem backwards from the logic?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Should be:

<perch:if exists="perch_item_first">