Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 有没有办法在液体中拆分空白文本?_Templates_Jekyll_Liquid - Fatal编程技术网

Templates 有没有办法在液体中拆分空白文本?

Templates 有没有办法在液体中拆分空白文本?,templates,jekyll,liquid,Templates,Jekyll,Liquid,我正在尝试将一篇Jekyll帖子的内容拆分为文字,并尝试了以下方法: {% for word in post.content | split:' ' %} {% do some stuff %} {% endfor %} 不幸的是,这没有任何作用“单词”作为整个帖子的结尾。我在Github页面上使用这段代码,所以很遗憾,我无法编写插件来处理这一问题。我是否错误地使用了拆分过滤器?Liquid是否支持我正在尝试的操作?过滤器(如split)只能在{{outputs}上使用,而不能在{%t

我正在尝试将一篇Jekyll帖子的内容拆分为文字,并尝试了以下方法:

{% for word in post.content | split:' ' %}
    {% do some stuff %}
{% endfor %}
不幸的是,这没有任何作用“单词”作为整个帖子的结尾。我在Github页面上使用这段代码,所以很遗憾,我无法编写插件来处理这一问题。我是否错误地使用了拆分过滤器?Liquid是否支持我正在尝试的操作?

过滤器(如split)只能在{{outputs}上使用,而不能在{%tags%}上使用

您可以使用捕获功能完成拆分,如下所示:
{%capture'foo%%{{post.content | split:'''}{%endcapture%}

您似乎可以使用
split:
在空白处进行拆分

因此,您可以尝试以下方法:

{% capture words %}{{ post.content | split:  }}{% endcapture %}
或:

从我到目前为止的测试来看,似乎应该使用后者(assign标记),因为在将值分配给变量时,capture标记似乎对数组元素进行隐式连接

使用:

{% for post in site.posts limit:1 offset:6 %}
  {% assign words = post.content | split:  %}
  {% for word in words %}{{ word }} {% endfor %}
{% endfor %}
似乎复制了文章的全部内容。内部for循环中的空格很重要

现在需要注意的是,如果您需要将一些单词与空格重新连接在一起,那么join标记似乎需要在字符周围加引号,如:
join:'

编辑: 我最后还尝试对空白进行一些拆分,虽然它在我的开发环境中工作,但在Github页面上却不起作用。看起来Pages正在运行版本,而
split()
过滤器是在版本中引入的。我的开发环境运行的是2.4.1。希望我们能在Github上纠缠那些优秀的人,让他们更新他们的液体版本。:)

{% for post in site.posts limit:1 offset:6 %}
  {% assign words = post.content | split:  %}
  {% for word in words %}{{ word }} {% endfor %}
{% endfor %}