I was wondering if is there any way to construct a hash variable in Jekyll/Liquid.
Maybe something like this:
{% assign x = { foo: 1, bar: 2 } %}
{{ x[foo] }}
{{ x[bar] }}
I was wondering if is there any way to construct a hash variable in Jekyll/Liquid.
Maybe something like this:
{% assign x = { foo: 1, bar: 2 } %}
{{ x[foo] }}
{{ x[bar] }}
There is no filters to work on hashes except the for
loop.
The only way to get a hash is from global or pages variables, data or collection.
A generator plugin can do some computing before rendering.
You can also manipulate arrays. For now only with push
and unshift
as pop
and shift
are changing their behavior in Jekyll 3.
In _config.yml
add a emptyArray: []
In your code just {% assign myarray = site.emptyArray %}
.
You can now push
and unshift
anything in it like {% assign myarray = myarray | push: "toto" %}
or any object/hash like page, post, data,...