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

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

Jekyll Liquid Exception for Unknown custom tag

问题

  1. 我已创建一个自定义的Jekyll液体标签
  2. ```ruby
  3. # my_tag.rb
  4. module Jekyll
  5. class MyTag < Liquid::Tag
  6. def initialize(tag_name, markup, tokens)
  7. super
  8. @title = markup['title']
  9. @step = markup['step']
  10. end
  11. def render(context)
  12. output = "<div>"
  13. output += "<h1>#{@title} #{@step}</h1>"
  14. output += "<p>#{super}</p>"
  15. output += "</div>"
  16. output
  17. end
  18. end
  19. end
  20. Liquid::Template.register_tag('my_tag', Jekyll::MyTag)

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

  1. {% my_tag title="hello" step="world" %}
  2. This is the data
  3. {% endmy_tag %}

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

  1. <details>
  2. <summary>英文:</summary>
  3. 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

  1. def render(context)
  2. output = &quot;&lt;div&gt;&quot;
  3. output += &quot;&lt;h1&gt;#{@title} #{@step}&lt;/h1&gt;&quot;
  4. output += &quot;&lt;p&gt;#{super}&lt;/p&gt;&quot;
  5. output += &quot;&lt;/div&gt;&quot;
  6. output
  7. end
  8. end

end

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

  1. And I&#39;m using it in following way in a markdown post
  2. ```markdown
  3. {% my_tag title=&quot;hello&quot; step=&quot;world&quot; %}
  4. This is the data
  5. {% 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:

确定