英文:
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 = "<div>"
output += "<h1>#{@title} #{@step}</h1>"
output += "<p>#{super}</p>"
output += "</div>"
output
end
end
end
Liquid::Template.register_tag('my_tag', Jekyll::MyTag)
And I'm using it in following way in a markdown post
```markdown
{% my_tag title="hello" step="world" %}
This is the data
{% endmy_tag %}
But it gives error Liquid Exception: Liquid syntax error (line 351): Unknown tag 'endmy_tag'
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论