8.4.1 How to make and assign text attribute to custom category object?
Permalink
I know how to add attributes to pages in the Dashboard and then to use them in code. But creating and assigning attributes to a custom category object programmatically doesn't work for some reason.
How to make and assign a text attribute to a custom category object?
Thank you.
How to make and assign a text attribute to a custom category object?
Thank you.
Let me make sure I got this correct. You want to create a custom category AKA a custom set then put a custom attribute with in that set. Then output the new custom attribute in a block programmatic use php. Like in a custom template correct?
Yes, that's correct.
I created a custom object category 'car'. I want to associate an attribute with that category, e.g. 'fuel', so that I can filter the cars by fuel.
I've already done this functionality directly in the DB as a 'fuel' field. But this makes me hard code the same fuel variable and then use the switch/case in single pages, controllers, views etc. I want the flexibility of a single attribute which I can use everywhere throughout the package.
I created a custom object category 'car'. I want to associate an attribute with that category, e.g. 'fuel', so that I can filter the cars by fuel.
I've already done this functionality directly in the DB as a 'fuel' field. But this makes me hard code the same fuel variable and then use the switch/case in single pages, controllers, views etc. I want the flexibility of a single attribute which I can use everywhere throughout the package.
If you are outputting to an existing block latest say the page list block so you can display a list of cars with a fuel type of say electric. I would use templates and the view.php file. Then look in the view for how it imports existing attributes (which I'm sure you have figured out). Then trace the attribute variable to the parent category and see if you can find the corresponding function. That way you can mimic that function for your custom set and attribute. Sorry I can't be more detailed my php skills are bad now days. lol.
I've got my own object 'Car', my own object list 'CarList', my own pages with my own blocks: one with list of cars and the other with details of each car.
Currently I store all car features in the DB. But some of them, especially those with options (e.g. fuel, gear box, body style, No of doors etc.), are hard coded in multiple places with select inputs and switch/case code. I want to change them for C5 attributes. This way I set up the attribute once and then reuse it throughout.
The problem is that the documentation page I followed doesn't work and it mixes up attributes from pages, themes, categories, Express etc. I can't find it anywhere how to add an attribute to a custom object category which would have worked.
Currently I store all car features in the DB. But some of them, especially those with options (e.g. fuel, gear box, body style, No of doors etc.), are hard coded in multiple places with select inputs and switch/case code. I want to change them for C5 attributes. This way I set up the attribute once and then reuse it throughout.
The problem is that the documentation page I followed doesn't work and it mixes up attributes from pages, themes, categories, Express etc. I can't find it anywhere how to add an attribute to a custom object category which would have worked.
I get it. This one over my php skills. But these post might help. If you still can't get it ask the guys in the C5 slack group. They can point you in the right direction for sure.
1.https://documentation.concrete5.org/developers/attributes/advanced-c...
2.https://www.concrete5.org/community/forums/customizing_c5/custom-obj...
1.https://documentation.concrete5.org/developers/attributes/advanced-c...
2.https://www.concrete5.org/community/forums/customizing_c5/custom-obj...