Ruby / Jekyll插件-如何在插件内部渲染液体变量

问题描述 投票:0回答:1

我正在创建一个Jekyll插件,该插件执行带有一些(无论是否为液体)参数的Shell脚本。

我在扩展某些液体变量的值时遇到问题。例如,如果我以这种方式使用此插件:

{% shellcmd image-responsive "{{ include.asset }}" %}

它没有渲染{{ include.asset }}部分。我需要帮助,尤其是这部分。

到目前为止,该插件是这样的:

module Jekyll
  class ShellCommand < Liquid::Tag

    def initialize(tag_name, text, tokens)
      super
      @text = text
    end

    def render_variable(context)
      Liquid::Template.parse(@text).render(context)
    end

    def render(context)
      text = render_variable(@text)
      `#{text}`.strip
    end
  end
end

Liquid::Template.register_tag('shellcmd', Jekyll::ShellCommand)

应该如何?

ruby jekyll liquid jekyll-extensions
1个回答
0
投票

没有检查代码中的内容,只是开始与Jekyll玩耍,所以也许我错了。但是,请尝试{% shellcmd image-responsive include.asset %}(您的行没有大括号)。

© www.soinside.com 2019 - 2024. All rights reserved.