在Jekylls Front Matter中使用变量 [英] Using variables in Jekylls Front Matter
本文介绍了在Jekylls Front Matter中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个包含通常用于帖子的图像的数据文件.
I have created a data file with images which I use normally for posts.
ImageKey:
- url: "/assets/logos/Image.png"
title: "Image Title"
现在,我想在帖子标题中使用此图像路径.
Now I want to use this image paths in my post headers.
---
layout: page
image:
- site.data.images.ImageKey
---
我的HTML看起来像
{% for image in page.images %}
<div>
<div class="img-thumbnail">
<img class="img-responsive" src="{{site.baseurl}}{{image.url}}" alt="{{image.title}}">
</div>
</div>
{% endfor %}
但是这里有什么问题.将不会渲染图片.
But anything is wrong here. There will no picture be rendered.
如果我直接在页首问题中使用值,则可以使用.
It works if I use values in the fronter matter directly.
---
layout: page
image:
- url: "..."
title: "..."
---
推荐答案
我已经解决了问题/请求.
I have the problem / request solved.
我的_data\images.yml
看起来像
Image_Key_Name
url: /assets/file.png
alt: ....
title: ....
copyright: ....
我的_posts\postXYZ.md
---
layout: post
author: Ben
titleImages:
- Image_Key_ Name
- Another_Image_Key_Name
abc...
---
还有我的_layouts\post.html
现在遍历键并将其用作数组索引.
now iterates over the keys and uses them as array index.
<div class="title-images">
{% for titleImageKey in page.titleImages %}
{% assign titleImage = site.data.images[titleImageKey] %}
<img src="{{site.baseurl}}{{titleImage.url}}" alt="{{titleImage.title}}" />
{% endfor %}
就是这样!
这篇关于在Jekylls Front Matter中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文