液体过滤器在管链内访问自身

Liquid filter access itself within pipe chain

这个有效:

{% assign getWord = "hello world" | split: " " %}
{% assign getWord = getWord[0] %}
{{ getWord }}

我只是想知道是否可以像这样在一行中完成同样的事情:

{% assign getWord = "hello world" | split: " " | this[0] %}
{% assign getWord = "hello world" | split: " " [0] %}
{% assign getWord = "hello world" | split: " " | [0] %}
{% assign getWord = "hello world" | split: " " | getWord[0] %}

这将解决您需要访问索引 0 和最后一个索引的确切问题。

{% assign getWord1 = "hello world" | split: " " | first %}
<!-- Test 1: {{ getWord1 }} == hello -->
{% assign getWord2 = "hello world" | split: " " | last %}
<!-- Test 2: {{ getWord2 }} == world -->
{% assign getWord3 = "hello world" | first %}
<!-- Test 3: {{ getWord3 }} == h -->