Kevin Sadler Kevin Sadler - 1 year ago 106
Twig Question

In Pico CMS content markdown file how to define an array

In my simple Pico (0.9) based website I would like to add category pages that would list a set of objects, different for each category and defined in the markdown file for each category. In theory it should then be possible to list them in the twig template using the

{% for object in set %}

I have happily been getting my own variables from the
files using my own plugin which maps my custom
Key Value Pair Label:
onto a custom field in the
variable in the template. But I just cannot get it to work with arrays.

Apparently the markdown header uses YAML and I have read the specification for that and there are a number of ways to specify such a list. So I have tried things like...

Title: Example Category Page - Cutlery
My Items: ['fork', 'spoon', 'knife']

Or this:

Title: Example Category Page - Cutlery
My Items:
- fork
- spoon
- knife

But when this is loaded in the template (with my plugin mapping it to
) with code like this:

{% for item in meta.my_items %}
<p>{{ item }}</p>
{% endfor %}

Nothing is displayed as if the array
is empty.

Ideally I would want to expand the objects in the array from simple strings to a set of KVPs (title, image, description) which I should be able to do in YAML.

So my question is - is this actually supported in Pico CMS and if so what am I doing wrong?

Answer Source

I tried (with the version 1.0) but the only working solution i found was about renaming it in the definition with an uderscore in the name. So try this:

My_Items: ['fork', 'spoon', 'knife']

instead of this:

My Items: ['fork', 'spoon', 'knife']

Hope this help.