Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

jekyll - Assign an array literal to a variable in Liquid Template

The only way i know to create an array from my liquid template is:

{% assign my_array = "one|two|three" | split: "|" %}

Is there any other way to do it?

question from:https://stackoverflow.com/questions/22763180/assign-an-array-literal-to-a-variable-in-liquid-template

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Frontmatter

This is a good workaround, add to the top of your file:

---
my_array:
  - one
  - two
  - three
---

then use it as:

{{ page.my_array }}

Analogous for site wide site.data.my_array on the _config or under _data/some_file.yml.

Jekyll 3 update for layouts

If the frontmatter is that of a layout, you need to use:

{{ layout.style }}

instead. See: https://stackoverflow.com/a/37418818/895245


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...