Jekyll Liquid异常,未知自定义标签

huangapple go评论48阅读模式
英文:

Jekyll Liquid Exception for Unknown custom tag

问题

我已创建一个自定义的Jekyll液体标签
```ruby
# my_tag.rb
module Jekyll
    class MyTag < Liquid::Tag
      def initialize(tag_name, markup, tokens)
        super
        @title = markup['title']
        @step = markup['step']
      end

      def render(context)
        output = "<div>"
        output += "<h1>#{@title} #{@step}</h1>"
        output += "<p>#{super}</p>"
        output += "</div>"
        output
      end
    end
end

Liquid::Template.register_tag('my_tag', Jekyll::MyTag)

而我在Markdown文章中如下方式使用它

{% my_tag title="hello" step="world" %}
This is the data
{% endmy_tag %}

但它出现错误Liquid Exception: Liquid syntax error (line 351): Unknown tag 'endmy_tag'


<details>
<summary>英文:</summary>

I have created a following custom Jekyll liquid tag

my_tag.rb

module Jekyll
class MyTag < Liquid::Tag
def initialize(tag_name, markup, tokens)
super
@title = markup['title']
@step = markup['step']
end

  def render(context)
    output = &quot;&lt;div&gt;&quot;
    output += &quot;&lt;h1&gt;#{@title} #{@step}&lt;/h1&gt;&quot;
    output += &quot;&lt;p&gt;#{super}&lt;/p&gt;&quot;
    output += &quot;&lt;/div&gt;&quot;
    output
  end
end

end

Liquid::Template.register_tag('my_tag', Jekyll::MyTag)


And I&#39;m using it in following way in a markdown post
```markdown
{% my_tag title=&quot;hello&quot; step=&quot;world&quot; %}
This is the data
{% endmy_tag %}

But it gives error Liquid Exception: Liquid syntax error (line 351): Unknown tag &#39;endmy_tag&#39;

答案1

得分: 0

我知道标签内不能包含数据。所以我不得不用Liquid::Block替换Liquid::Tag来解决这个问题。

英文:

I got to know that a tag can't have data within. So I had to replace Liquid::Tag with Liquid::Block to solve the issue

huangapple
  • 本文由 发表于 2023年4月4日 11:52:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925390.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定