9

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] }}
Linlin Yan
  • 91
  • 3

1 Answers1

7

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.

Recipe

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,...

David Jacquel
  • 51,670
  • 6
  • 121
  • 147