Forum

Thread tagged as: Question, Problem, Addons

Sub-Categories in Templates

Hi,

A brief overview of my categories;

  • We have 1 set, 4 Categories, and each Category has a collection of subcategories.

Now, I'm trying to set up a content template, so that users can define which subcategory the added content fits into.

So far, I've added this to my template html

<perch:categories id="category" set="message-category" label="Category" required="true" >
    <perch:category id="catTitle" type="smarttext" label="Title" required="true"/>
</perch:categories>

This has 2 problems;

1) Each Content item has to fit into a subcategory - but this way lets them choose categories as well as subcategories. For example, A Cat is a Mammal, and a Mammal is an Animal - I don't want the user to be able to tag the cat as an Animal, but simply to say what subcategory it fits in (here, a mammal) as it's meaningless to take a cat as both a mammal and an animal, since ALL mammals are animals (hence it being a subcategory of animals).

2) The tagging system also allows the user to select as many options as possible. I want to restrict it to ONE choice (I have seen you can add display-as to create checkboxes, is there a radio button alternative to limit to 1?)

I appreciate this is a fairly specific instance of subcategories - but I assume what I want should be possible. If not, I'll have to make some sourcecode adjustments I think.

Thanks for any advice!

Matthew Lymer

Matthew Lymer 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Those options aren't currently supported - simply because there's not been a lot of demand for them yet.

Ah - darn.

Well I can handle point 2 by just only using the first non-parent category selected for each piece of content.

As for point 1, I suppose I'll just have to let them choose to give each piece of content main category tags as well as sub-category tags, but make sure my custom functions ignore any category with parentID of 0.

Thanks anyway!

Drew McLellan

Drew McLellan 2638 points
Perch Support

We'll certainly consider the additions. Limiting the number of selections should be very straightforward to add, as the UI widget already supports it, we just need to pass the data through from the template.

Great!

On a similar not, I am trying to display the Category ID of a category in my content template.

Using the catTitle works;

<perch:categories id="mediaCats" set="media-types" label="Media (Select 1)">
<perch:category id="catTitle" />
</perch:categories>

But if I try to show the catPath or _id, it doesn't work;

<perch:categories id="mediaCats" set="media-types" label="Media (Select 1)">
<perch:category id="catPath" />
</perch:categories>

I know catPath and _id are defined, as I can pull out the data using perch_categories() - but surely what I am trying should be possible?

Sorry to change the subject of the issue, but I have solved my problem and found another;

Because this was all happening in a repeater, I have to work inside the repeater to get the categories to work (also I tried _id instead of catID).

I've got the catID working now, which is good!

However, my new found problem is with;

<perch:content id="_id" type="hidden" />

This works fine in the template, but NOT inside a repeater. The problem is I NEED it inside the repeater, as I need to use the ID of the current content as a unique identifier for a series of input boxes in the repeater...

Again, sorry, I just discovered the genius that is "scope-parent=true" - great!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Perfect!