How to create maps of keyword and values?

I suppose this should be evident for people used to liquid syntax, but I don’t find how to do it.

I have to create a list of objects with properties and values in a variable to pass it to an include, and don’t know how to do it.
I have tried using capture/endcapture and strings, but
Something like this:

sections= [
  {
    name= "Sec1"
    prefix= "prefixSec1"
    cats= [
      {
        name= "sec1cat1"
        prefix= "prefixSec1Cat1"
      },
      {
        name= "sec1cat2"
        prefix= "prefixSec1Cat2"
      }]
  },
  {
    name= "Sec2"
    prefix= "prefixSec2"
    cats= [
      {
        name= "sec2cat1"
        prefix= "prefixSec1Cat1"
      },
      {
        name= "sec2cat2"
        prefix= "prefixSec2Cat2"
         {
        name= "sec2cat3"
        prefix= "prefixSec2Cat3"
       }]
  }
]

The idea is to be able to access the elements i other parts of the code using loops like

{% for s in sections %}
   <p>{{ s.name }}</p>
   <ul>
   {% for c in s.cats %}
       <li>{{ c.name }} </li>
   {% endfor %}
   </ul>
{% endfor %}

But I don’t find how to construct the sections variable dinamically by code.

How do you create a list of keyword/value pairs and how do you include that in other object?

YAML is good for this, preferably in a data file but can be in other places. I have always used this as a reference, lots of use cases:

Yes, but may be I have not explained it correctly.

I know I can do that kind of structures in a source file, create a list like that and then using liquid navigate that lists.

But I am trying to create that objects in memory dynamically using liquid.

I need to extract info from the collections, create a list with that structure and pass it to theme includes that expect the data collection be organized with some specific structure.

Let me simplify the example to the maximum

I want to create a key/valu pair using liquid, something like
{% assign s=’{“name”,“value”} %}

Process s with whatever filter is appropiate (split?)
{% assign v= s|filterx %}

and the be able to do:

{{v.name}}

and get

value</p

as output.

Construct object dinamically

like this? though that is just values not key pairs.

maybe this:

If not, more info on your use case would help - sometimes the thing you are trying to accomplish can be done in a different way than the specific thing you are asking, though it sounds like you know what you are doing so you are probably fine.

I don’t work much with arrays like that, others may have a lot better info.

and to be clear - it looks like your issue is in using the array, not creating it?

So, you only can create arrays and access it numeric ID?
I mean i that example, after splitting the array you have to access the key/valu pairs as
pair_arr[0] for the key and pair_arr[1] for the value.

You cannot access the object by the key name?, something like

{ book.title } (should display title1)

you have to search for the pair that has “tittle” in pair_arr[0] and then get the value in pair_arr[1].

I was trying to reuse some includes that relay in passing them collections of elements like pages collection.

So the list of categories I pass them should have the same properties.

I can construct an array, but if you have to access it using the position and it won’t work.

I would like to pass them a collection of elements constructed for infor extracted from other elements, but that it is not in a source file.

For example pass a list of collection and subcategories to an include that expect a collection of pages to generate a menu using the title of the pages.

I don’t know - I’m don’t really use arrays like that, so can’t really help much. Hopefully someone else will chime in, I can’t really say one way or another, most of what I do is using a data file.

Thank you.

I am finding some limitations in jekyll.

Will investigate other solutions too.