Forum
Any way to avoid hard-coding category sets into template files?
I have a collection of articles which are categorised using categories and sets. Is there a way to include the category checkboxes from all existing sets in my article template without having to explicitly name each set?
I would like for the client to be able to add new sets without having to update the article template every time. Is this possible?
Here's one of the hard-coded categories / sets excerpt from my article.html template:
<perch:categories id="overview" label="Back Pain Overview" set="back-pain-overview" display-as="checkboxes" order="5">
<a href="/category/<perch:category id="catPath" />"><perch:category id="catTitle" /></a>
</perch:categories>
Is there a way to loop through all available sets in the template & swap out the id / label / set attribute values for each?
If not, is there a better way to handle this?
Is there a reason to have them as distinct sets rather than nested categories within one set?
It's a big site with a lot of articles (100+) in 40+ categories so the categories are grouped into sets (probably no more than 10). This provides the basis for the navigation, i.e.
Each category page contains an introduction and a list of articles in that category.
Ok, I see. There's not a way to dynamically list sets.
Shoot. Any plans to implement something like this in the future?
Would you recommend building the site using pages instead? i.e. articles as subpages of category pages nested within sections.
Based on your recommendation here and even with the restriction of having to fix the sets, using categories and collections certainly feels like the better way to go.
Are there are any benefits or issues with performance to either approach?
I would still go with that approach. I guess I'd always thought that nested categories would be used for this rather than multiple sets.
Thanks Drew, nested categories sounds hopeful - didn't occur to me that this was possible. How would I do that? Any examples /docs? Thanks again for the quick response.
It may not work for you in this circumstance - but you can nest categories by adding new subcategories, or by going to the Reorder page and dragging them around.
Awesome, seems so obvious now! Thanks for that; I'll investigate this approach further!
Last question (on this thread), I promise! If this proves successful, is there a way to easily move categories from one set to another? I already have a fair bit of formatted content in existing category descriptions.
There's not an automated way, but I can show you how to change it in the database if that will save you some time.
Thanks Drew. Is it just a matter of editing the setID, catParentID, catPath & catTreePosition fields in the perch2_categories table?
Yes, that's right.
Excellent thanks, I'll give that a try.