【问题标题】:Jekyll - Pass a jekyll variable to a custom liquid tagJekyll - 将 jekyll 变量传递给自定义液体标签
【发布时间】:2016-07-07 01:37:27
【问题描述】:

我正在尝试研究如何将 Jekyll 变量传递给液体标签插件。 我试过这样做:

{% liquidtag {{ variable }} %}

但是变量并没有被实现,标签只是接收到带有大括号的变量名:{{ variable }}

当我使用:{% liquidtag {% variable %} %} - 变量包含在字符串中之前的 {% 和变量与液体标签的第一个 {% 匹配之后的 %} 时,它也没有实现 -最后关闭的%} 被忽略。即,这通过了: {% 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>
...

【问题讨论】:

标签: variables plugins jekyll liquid


【解决方案1】:

经过大量搜索,我终于找到了答案。我不知道为什么我以前很难找到!抱歉重复的问题!
这是我找到的答案:

using Liquid variables inside of a liquid tag call

【讨论】:

  • 我找到了你的问题 DuckDuckGo'ing 我的问题,所以谢谢你的重复!
猜你喜欢
  • 2020-02-21
  • 2014-02-04
  • 2016-05-04
  • 1970-01-01
  • 1970-01-01
  • 2021-07-11
  • 1970-01-01
  • 2020-05-15
  • 1970-01-01
相关资源
最近更新 更多