使用 Jekyll 注释掉 HTML 文件中的 include 语句

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

有没有办法使用 Jekyll 注释掉 HTML 文件中的 include 语句?

例如,我的一个 HTML 文件中有此内容,我想暂时注释掉它。标准 HTML 注释似乎不起作用。

{% include navbar.html %}           
comments jekyll
4个回答
118
投票
{% comment %}
{% include navbar.html %}
{% endcomment %}

22
投票

Jekyll 使用 Liquid 模板系统。因此,任何适用于 Liquid 的东西也适用于 Jekyll。

{% comment %}
this is commented out
{% endcomment %}

https://shopify.github.io/liquid/tags/template/#comment


1
投票

mccambridge 发布了正确的解决方案。 David Jacquel 发布的内容在 Jekyll 中不起作用。 或者,您可以在括号 { 和百分比符号 % 之间添加空格,如下所示:

{% comment %}
{ % include navbar.html % }
{% endcomment %}

0
投票

由于 jekyll 在 html 中使用,我认为这样做更好

  1. 括号和百分号之间留一个空格
  2. 将其包含在 html 注释中
<div>
    <!-- { % for i in (1..100) % } -->
    {% for post in site.posts %}
        <a href="{{post.url}}"> {{post.title}}</a>
    {% endfor %}
    <!-- { % endfor % } -->
    
</div>

上面的代码对我来说是一个非常常见的用例,我想模拟很多帖子来调试我的用户界面

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