Forum
Using else to display error for missing category
I'm testing/researching using categories for a project using the portfolio categories example in the docs.
I have a problem where if there's "no" portfolio item with a given category is should display a "nothing here" error.
- I'm displaying a list of portfolio items on the URL category.php?cat=products/forestry/
<perch:before>
<ul>
</perch:before>
<li>
<a href="detail.php?s=<perch:content id="slug" type="slug" />">
<perch:content id="image" type="image" width="100" height="100" crop="true" output="tag" />
<perch:content id="title" type="text" />
</a>
</li>
<perch:after>
</ul>
</perch:after>
- The category page lists all the "forestry" titles in a list using...
<?php
if (perch_get('cat')) {
perch_category(perch_get('cat'),array(
'template'=>'category_single.html'
));
perch_content_custom('Portfolio', array(
'template' => 'portfolio_listing.html',
'page'=>'/portfolio.php',
'category' => perch_get('cat'),
));
} else {
perch_categories(array(
'set' => 'Products',
));
}
?>
- If there's no portfolio items yet allocated to "forestry" no list is displayed. So to create an error the portfolio_listing.html I'm using...
<perch:before>
<ul>
</perch:before>
<li>
<perch:if exists="title">
<a href="detail.php?s=<perch:content id="slug" type="slug" />">
<perch:content id="image" type="image" width="100" height="100" crop="true" output="tag" />
<perch:content id="title" type="text" />
</a>
<perch:else />
<p>Sorry nothing here!</p>
</perch:if>
</li>
<perch:after>
</ul>
</perch:after>
This does not work and outputs nothing. Where am I going wrong?
If there's nothing to template, the template isn't used - except if it has a
noresults
section.https://docs.grabaperch.com/docs/templates/noresults/
Ah! of course. Thanks.