Jekyll - 将 jekyll 变量传递给自定义液体标签
Jekyll - Pass a jekyll variable to a custom liquid tag
我正在研究如何将 Jekyll 变量传递给 liquid 标签插件。
我试过这样做:
{% liquidtag {{ variable }} %}
但是变量没有被实现,标签只是接收到带有大括号的变量名:{{ variable }}
当我使用时也没有实现:{% liquidtag {% variable %} %}
- 变量包含在字符串中之前的 {%
和变量与第一个匹配之后的 %}
liquid 标签的 {%
- 最后一个关闭 %}
被忽略。即,这会通过:
{% variable
我想要的是将变量的实际值传递给标签。
这是标签:
class CatAbs < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
puts @text
end
def render(context)
return @text.split("-").at(1)
end
end
这是我目前引用标签的方式:
{% for tag in site.categories %}
<div class="grid grid-pad">
<a><h2>{% CatAbs {{ tag[0] }} %} »</h2></a>
...
经过大量的搜索,我终于找到了答案。我不知道为什么我以前很难找到它!抱歉重复的问题!
这是我找到的答案:
using Liquid variables inside of a liquid tag call
我正在研究如何将 Jekyll 变量传递给 liquid 标签插件。 我试过这样做:
{% liquidtag {{ variable }} %}
但是变量没有被实现,标签只是接收到带有大括号的变量名:{{ variable }}
当我使用时也没有实现:{% liquidtag {% variable %} %}
- 变量包含在字符串中之前的 {%
和变量与第一个匹配之后的 %}
liquid 标签的 {%
- 最后一个关闭 %}
被忽略。即,这会通过:
{% variable
我想要的是将变量的实际值传递给标签。
这是标签:
class CatAbs < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
puts @text
end
def render(context)
return @text.split("-").at(1)
end
end
这是我目前引用标签的方式:
{% for tag in site.categories %}
<div class="grid grid-pad">
<a><h2>{% CatAbs {{ tag[0] }} %} »</h2></a>
...
经过大量的搜索,我终于找到了答案。我不知道为什么我以前很难找到它!抱歉重复的问题!
这是我找到的答案:
using Liquid variables inside of a liquid tag call