Forum OpenACS Development: Categories with extra attributes

Collapse
Posted by Iuri Sampaio on
Hi there,

Assuming I want to use categories package to support customized content items, but I just want them slightly different. I want the possibility to add an SVG icon to each category.

At first, I've thought if I had added any bootstrap source directly within the category title, it would work out off the box. But, then of course, nothing is too easy!

What would be a better approach to attach an SVG icon to categories?

Do I need to create my own datamodel?

Best wishes,
Iuri

Collapse
Posted by Dave Bauer on
This depends on exactly what you want to do.

If you embed HTML in the category title, and you display it with ;noqute it generally would work, but that introduces a security problem if untrusted users can set the category title.

It seems like that best technique would be to assign a CSS class derived from the category name or path.

If you are talking about displaying the category in your own code templates, you would then write a Tcl procedure that generates the css class name based on the category and use that in the templates. This way you aren't adding any complex structure or code needed to maintain the icons.

If you need to store the icon data in the database from an administrative user interface, then you could create a mapping table to store the svg data with a foreign key to the category id.

If categories are objects you could also use acs-object-management or you own custom code to extend the category object with custom attributes.

Collapse
Posted by Iuri Sampaio on
Thanks Dave!

"If you need to store the icon data in the database from an administrative user interface, then you could create a mapping table to store the svg data with a foreign key to the category id."

This option will be the one.