首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jekyll条件图像标记在不存在时仍会显示

Jekyll条件图像标记在不存在时仍会显示
EN

Stack Overflow用户
提问于 2016-02-08 03:56:12
回答 1查看 133关注 0票数 0

我正在为我的网站使用Jekyll,并且我有以{% if page.second-image %}开始并以{% endif %}结束的有条件的附加图像。不幸的是,即使帖子中没有第二张图片,这些图片标签仍然会出现。如果它们没有编码到当前帖子中,我如何让Jekyll忽略它们?谢谢!!

代码语言:javascript
复制
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

但是,来自帖子模板的第四、第五和第六张图片显示为断开的链接,即使它们不在那里

EN

回答 1

Stack Overflow用户

发布于 2016-02-08 05:03:54

好的,试试这个:

代码语言:javascript
复制
---
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文件):

代码语言:javascript
复制
{% if page.second-image %} <img class="some_class" src="{{ site.baseurl }}/img/{{ page.second-image }}" alt="{{ page.title }}"> {% endif %} 

或者:

代码语言:javascript
复制
---
extra_imgs: [path1.png, path2.png, path3.png]
---

然后

代码语言:javascript
复制
{% 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前件值中使用特殊字符。他们可以在他们之后破解密码!无论如何,如果,你应该是好的。

让我知道它进行得怎么样!

希望能有所帮助!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35258325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档