DNS*_*DNS 3 templates liquid jekyll
我正在尝试将Jekyll帖子的内容分成单词,并尝试了以下内容:
{% for word in post.content | split:' ' %}
{% do some stuff %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这没有做任何事情; 'word'最终成为整个帖子.我在Github Pages上使用这个代码,所以不幸的是我无法编写插件来处理这个问题.我错误地使用了拆分过滤器吗?Liquid是否支持我正在尝试做的事情?
And*_*rew 10
It seems that you can split on whitespace by using split: .
So you can try something like:
{% capture words %}{{ post.content | split: }}{% endcapture %}
Run Code Online (Sandbox Code Playgroud)
or:
{% assign words = post.content | split: %}
Run Code Online (Sandbox Code Playgroud)
From what I've tested so far it seems that you should use the latter (assign tag), as the capture tag seems to do an implicit join on the array elements when assigning the value to the variable.
Using:
{% for post in site.posts limit:1 offset:6 %}
{% assign words = post.content | split: %}
{% for word in words %}{{ word }} {% endfor %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
seems reproduce the post content in its entirety. The whitespace in the inner for loop matters.
Just as a note now, if you need to join some of the words back together with whitespace, the join tag seems to require quotes around the character, like so: join:' '.
我最终试图在空白上进行一些拆分,虽然它在我的开发环境中工作但它在Github Pages上不起作用.它看起来像是运行版本2.2.2,而split()过滤器是在2.3.0版本中引入的.我的开发环境正在运行2.4.1.希望我们可以纠结Github上的好人,让他们更新他们的Liquid版本.:)