Question

I'm currently playing with Locomotive CMS, and have created a Model via the control panel. Within that model I have created a select menu called "category". It looks something like this in yaml :

- category:
    label: Category
    type: select
    required: true
    select_options: *70168253718360

Basically I want to loop over all of the various entries in this model, but sort them by category, and insert a header for each category... I've done a bunch of reading in the locomotivecms documentation, but somehow this escapes me. I could see creating a model for each, but that would quickly become a mess as I'm going to have quite a few, and of course, is repeating a task over and over a lot.

Does anyone know if this is somehow possible? Or if there's a better way to go about this? Thank you very much!

Was it helpful?

Solution

There is two ways you could do this. The first would be simpler, you would add a select field to the model. Under the presentation section of edit model page, you will be able to select a group by. Select your new field and then when you loop over the model you will be passed a hash instead of an array. The second option is to create a second model and create a belongs to/has many relationship between your first model and the new one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top