【问题标题】:Nested liquid custom tag blocks嵌套的液体自定义标签块
【发布时间】:2016-08-25 00:39:05
【问题描述】:

如果外部标签包含多个同级液体标签,我无法编译一些嵌套的液体标签。这有效:

{% container %}
  {% inner %}
    Stuff Goes in here
  {% endinner %}
{% endcontainer %}

但这不是

{% container %}
  {% inner %}
    Stuff Goes in here
  {% endinner %}
  {% inner %}
    Stuff Goes in here
  {% endinner %}
{% endcontainer %}

我收到以下错误:

Liquid Exception: Liquid syntax error (line 1): 'container' tag was never closed in /.../_posts/blah.markdown/#excerpt
Liquid Exception: Liquid syntax error (line 1): 'container' tag was never closed in _includes/head.html, included in _layouts/default.html

注意到第一个错误中的#excerpt?如果我在前面的内容中添加摘录。一切正常。我的 head.html 包含是默认包含一个新的 jekyll 站点:

  <meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">

删除头部的 if 语句也会使错误消失。我完全不明白为什么有多个兄弟姐妹会导致这个错误。这是我的简化插件代码:

module Jekyll
  class RenderContainer < Liquid::Block

    def initialize(tag_name, contain, tokens)
      super
    end

    def render(context)
      "<div class=\"container\">#{super}</div>"
    end
  end

  class RenderInner < Liquid::Block
    def initialize(tag_name, contain, tokens)
      super
    end

    def render(context)
      "<div class=\"inner\">#{super}</div>"
    end
  end
end

Liquid::Template.register_tag('container', Jekyll::RenderContainer)
Liquid::Template.register_tag('inner', Jekyll::RenderInner)

【问题讨论】:

    标签: ruby jekyll liquid


    【解决方案1】:

    我刚刚遇到了同样的问题,显然这是known bug。我试过你的插件和你无法在上面工作的液体标签:

    {% container %}
      {% inner %}
        Stuff Goes in here
      {% endinner %}
      {% inner %}
        Stuff Goes in here
      {% endinner %}
    {% endcontainer %}
    

    ...一旦我将推荐的修复程序(见下文)添加到我的config.yml,之后代码就可以工作了。

    excerpt_separator: ""
    

    注意,请务必在将此位添加到配置文件后重新启动 Jekyll 服务。

    【讨论】:

    • 不错!感谢您回答一个近一年的问题!
    猜你喜欢
    • 1970-01-01
    • 2022-06-14
    • 2015-06-11
    • 2018-01-03
    • 2016-07-07
    • 2011-12-15
    • 2019-01-23
    • 2014-12-26
    • 2013-10-14
    相关资源
    最近更新 更多