访问 collection 文档中的自定义前端变量
Accessing custom front matter variable in collection documents
我在 collection coding
:
中有一个 Jekyll collection 文档
---
title: 'iOS iConify'
rawname: iosiconify
image: {{site.img}}/z-iosiconify.png
layout: post
link: https://iosiconify.github.io/
---
Hi!
我正在尝试在 html 页面上呈现 collection coding
中的所有文档,并且我有以下代码:
{% for post in site.coding %}
<tr id="{{ post.rawname }}-desktop">
<td id="left">
<a href="{{ post.link }}" target="blank" id="{{ post.rawname }}-desktop-a">
<img src="{{ post.image }}">
</a>
</td>
<td id="right">
<h2>{{ post.title }}</h2>
<h4>{{ post.content }}</h4>
</td>
</tr>
{% endfor %}
我在其中引用了很多我自定义的前端变量,例如 {{ post.rawname }}
。但是,当页面构建时,唯一有效的部分是 {{ post.content }}
.
这是渲染后的 HTML:
<tr id="-desktop">
<td id="left">
<a href="" target="blank" id="-desktop-a">
<img src="">
</a>
</td>
<td id="right">
<h2></h2>
<h4><p>Hi!</p>
</h4>
</td>
</tr>
您知道为什么 none 的自定义前端变量有效吗?我如何才能让它们起作用?
Front-matter 中存在错误,导致 Jekyll 无法正确处理它,仅显示内容。
这一行 image: {{site.img}}/z-iosiconify.png
应该是 image: z-iosiconify.png
。
然后在显示文档时像 {{ post.image | prepend: site.img }}
一样添加 site.img
。例如:
{% for post in site.coding %}
<tr id="{{ post.rawname }}-desktop">
<td id="left">
<a href="{{ post.link }}" target="blank" id="{{ post.rawname }}-desktop-a">
<img src="{{ post.image | prepend: site.img }}">
</a>
</td>
<td id="right">
<h2>{{ post.title }}</h2>
<h4>{{ post.content }}</h4>
</td>
</tr>
{% endfor %}
我在 collection coding
:
---
title: 'iOS iConify'
rawname: iosiconify
image: {{site.img}}/z-iosiconify.png
layout: post
link: https://iosiconify.github.io/
---
Hi!
我正在尝试在 html 页面上呈现 collection coding
中的所有文档,并且我有以下代码:
{% for post in site.coding %}
<tr id="{{ post.rawname }}-desktop">
<td id="left">
<a href="{{ post.link }}" target="blank" id="{{ post.rawname }}-desktop-a">
<img src="{{ post.image }}">
</a>
</td>
<td id="right">
<h2>{{ post.title }}</h2>
<h4>{{ post.content }}</h4>
</td>
</tr>
{% endfor %}
我在其中引用了很多我自定义的前端变量,例如 {{ post.rawname }}
。但是,当页面构建时,唯一有效的部分是 {{ post.content }}
.
这是渲染后的 HTML:
<tr id="-desktop">
<td id="left">
<a href="" target="blank" id="-desktop-a">
<img src="">
</a>
</td>
<td id="right">
<h2></h2>
<h4><p>Hi!</p>
</h4>
</td>
</tr>
您知道为什么 none 的自定义前端变量有效吗?我如何才能让它们起作用?
Front-matter 中存在错误,导致 Jekyll 无法正确处理它,仅显示内容。
这一行 image: {{site.img}}/z-iosiconify.png
应该是 image: z-iosiconify.png
。
然后在显示文档时像 {{ post.image | prepend: site.img }}
一样添加 site.img
。例如:
{% for post in site.coding %}
<tr id="{{ post.rawname }}-desktop">
<td id="left">
<a href="{{ post.link }}" target="blank" id="{{ post.rawname }}-desktop-a">
<img src="{{ post.image | prepend: site.img }}">
</a>
</td>
<td id="right">
<h2>{{ post.title }}</h2>
<h4>{{ post.content }}</h4>
</td>
</tr>
{% endfor %}