我正在为我的网站使用Jekyll,并且我有以{% if page.second-image %}开始并以{% endif %}结束的有条件的附加图像。不幸的是,即使帖子中没有第二张图片,这些图片标签仍然会出现。如果它们没有编码到当前帖子中,我如何让Jekyll忽略它们?谢谢!!
layout: post
title: title
date: 2015-09-02
image: /img/path.png
second-image: /img/path.png
third-image: /img/path.png
description: Landing Page/Menu Design
meta-title: meta title information但是,来自帖子模板的第四、第五和第六张图片显示为断开的链接,即使它们不在那里
发布于 2016-02-08 05:03:54
好的,试试这个:
---
title: "My title" # wrap in double quotes
image: path.png # remove source folder
second-image: path.png
description: "My description" # wrap in double quotes
meta-title: "meta title information" # wrap in double quotes
... # whatever you need
---然后,转到post.html (或从其中调用帖子的另一个html文件):
{% if page.second-image %} <img class="some_class" src="{{ site.baseurl }}/img/{{ page.second-image }}" alt="{{ page.title }}"> {% endif %} 或者:
---
extra_imgs: [path1.png, path2.png, path3.png]
---然后
{% if page.extra_imgs %}
{% for img in page.extra_imgs %}
<img class="some_class" src="{{ site.baseurl }}/img/{{ img }}" alt="{{ page.title }}">
{% endfor %}
{% endif %}提示:避免在yaml前件值中使用特殊字符。他们可以在他们之后破解密码!无论如何,如果,你应该是好的。
让我知道它进行得怎么样!
希望能有所帮助!
https://stackoverflow.com/questions/35258325
复制相似问题