If statement 杰基尔:在Includes中使用Front-Matter
是否可以在include中使用front-matter。我有一个名为If statement 杰基尔:在Includes中使用Front-Matter,if-statement,jekyll,liquid,If Statement,Jekyll,Liquid,是否可以在include中使用front-matter。我有一个名为image.html的include,看起来像这样 image.html {% if layout == 'page' %} <img src="{{ site.url }}/public/img/{{ include.url }}" class="page"> {% else %} <img src="{{ site.url }}/public/img/{{ include.url }}"> {
image.html
的include,看起来像这样
image.html
{% if layout == 'page' %}
<img src="{{ site.url }}/public/img/{{ include.url }}" class="page">
{% else %}
<img src="{{ site.url }}/public/img/{{ include.url }}">
{% endif %}
{% if include.size == 'full' and include.type != 'gif' %}
<section class="image full-width">
<img src="{{ site.url }}/public/img/{{ include.name }}.{{ include.type }}">
</section>
{% elsif layout == 'page' and include.type != 'gif' %}
<div class="container">
<div class="sm-col-12">
<section class="image">
<img src="{{ site.url }}/public/img/{{ include.name }}.{{ include.type }}">
</section>
</div>
</div>
{% elsif include.type != 'gif' %}
...
{% else %}
...
{% endif %}
但由于某些原因,它无法识别if布局
语句。你知道怎么让它工作吗
感谢您的帮助。提前谢谢
更新
全文如下:
如果页面上包含image.html
include,则include需要具有完全不同的布局,具有两个封装元素(container
和sm-col-12
)。希望下面的问题比我原来的问题更有意义
image.html
{% if layout == 'page' %}
<img src="{{ site.url }}/public/img/{{ include.url }}" class="page">
{% else %}
<img src="{{ site.url }}/public/img/{{ include.url }}">
{% endif %}
{% if include.size == 'full' and include.type != 'gif' %}
<section class="image full-width">
<img src="{{ site.url }}/public/img/{{ include.name }}.{{ include.type }}">
</section>
{% elsif layout == 'page' and include.type != 'gif' %}
<div class="container">
<div class="sm-col-12">
<section class="image">
<img src="{{ site.url }}/public/img/{{ include.name }}.{{ include.type }}">
</section>
</div>
</div>
{% elsif include.type != 'gif' %}
...
{% else %}
...
{% endif %}
在include文件中,仍然可以使用
页面
变量
在您的情况下,您需要调用page.layout
:
<img src="{{ site.url }}/public/img/{{ include.url }}" {% if page.layout == 'page' %}class="page"{% endif %}>
对不起。我发布的例子是我所面临问题的简化版本。实际上,我不能在.md
文件中使用'page'变量,而是需要在include文件中使用它。你知道这是否可行吗?你能给出完整的上下文吗。你是否在循环中,列出帖子或页面?在原始问题旁边发布了更新。我希望这能提供更多的背景…同样的答案{%elsif page.layout=='page'…
因为从image.html
内部,您仍然处于about.md
页面上下文中。因此,您仍然可以从page.layout
变量中访问about页面布局。啊哈!我错过了page.layout
中的page
。感谢您的帮助,并对疏忽表示歉意。