从 Liquid 中的字符串中获取子字符串?
Get substring from string in Liquid?
我正在使用 Jekyll,我有字符串 balh blah blah&garbage **&*&% garbage <h1>TITLE</h1> &^*$%"
有没有办法抢TITLE?我查看了函数 here,但我没有看到可以使用的东西。
split
救援!
{% assign str = 'garbage <h1>TITLE</h1> moregarbage' %}
{% assign a = str | split: '<h1>' %}
我们现在在 a[0] 中有 garbage
,在 a[1] 中有 TITLE</h1> moregarbage
{% assign b = a[1] | split: '</h1>' %}
我们现在在 b[0] 中有 TITLE
,在 b[1] 中有 moregarbage
我知道这很古老,但对于遇到它的其他人来说:https://shopify.github.io/liquid/basics/operators/
contains contains checks for the presence of a substring inside a
string.
{% if product.title contains "Pack" %} This product's title contains
the word Pack. {% endif %}
contains can also check for the presence of a string in an array of
strings.
{% if product.tags contains "Hello" %} This product has been tagged
with "Hello". {% endif %}
contains can only search strings. You cannot use it to check for an
object in an array of objects.
我正在使用 Jekyll,我有字符串 balh blah blah&garbage **&*&% garbage <h1>TITLE</h1> &^*$%"
有没有办法抢TITLE?我查看了函数 here,但我没有看到可以使用的东西。
split
救援!
{% assign str = 'garbage <h1>TITLE</h1> moregarbage' %}
{% assign a = str | split: '<h1>' %}
我们现在在 a[0] 中有 garbage
,在 a[1] 中有 TITLE</h1> moregarbage
{% assign b = a[1] | split: '</h1>' %}
我们现在在 b[0] 中有 TITLE
,在 b[1] 中有 moregarbage
我知道这很古老,但对于遇到它的其他人来说:https://shopify.github.io/liquid/basics/operators/
contains contains checks for the presence of a substring inside a string.
{% if product.title contains "Pack" %} This product's title contains the word Pack. {% endif %}
contains can also check for the presence of a string in an array of strings.
{% if product.tags contains "Hello" %} This product has been tagged with "Hello". {% endif %}
contains can only search strings. You cannot use it to check for an object in an array of objects.