你如何将 site.data 传递给包含在 Jekyll 中的包含?
How do you pass site.data to includes within includes in Jekyll?
每当我需要显示画廊时,我都会包含一段代码。
<!-- _includes/gallery.md -->
{% assign items = {{include.data}} %}
{% for item in items -%}
{% assign src = item.path | prepend: "/assets/images/" | relative_url %}
[![{{item.alt}}]({{src}}){:.gallery-{{items.size}}}]({{src}})
{%- endfor %}
{:.text-center}
我可以通过 site.data
填充画廊。
{% include gallery.md data = site.data.index.themes %}
我有一个需要显示画廊的模板页面。我也想传site.data
<!-- _includes/create-new.md -->
Create a new {{include.type}}:
{% include gallery.md data = {{include.site_data}} %}
但是当我尝试将 site.data
传递给模板页面时,出现错误。
{% include create-new.md type = "layout" site_data = site.data.index.layouts %}
如何将 site.data
传递给 includes 中的 includes?
无论是否嵌套在另一个包含标记中,都像传递任何其他数据一样简单地传递它:
<!-- _includes/create-new.md -->
Create a new {{ include.type }}:
{% include gallery.md data = include.site_data %}
每当我需要显示画廊时,我都会包含一段代码。
<!-- _includes/gallery.md -->
{% assign items = {{include.data}} %}
{% for item in items -%}
{% assign src = item.path | prepend: "/assets/images/" | relative_url %}
[![{{item.alt}}]({{src}}){:.gallery-{{items.size}}}]({{src}})
{%- endfor %}
{:.text-center}
我可以通过 site.data
填充画廊。
{% include gallery.md data = site.data.index.themes %}
我有一个需要显示画廊的模板页面。我也想传site.data
<!-- _includes/create-new.md -->
Create a new {{include.type}}:
{% include gallery.md data = {{include.site_data}} %}
但是当我尝试将 site.data
传递给模板页面时,出现错误。
{% include create-new.md type = "layout" site_data = site.data.index.layouts %}
如何将 site.data
传递给 includes 中的 includes?
无论是否嵌套在另一个包含标记中,都像传递任何其他数据一样简单地传递它:
<!-- _includes/create-new.md -->
Create a new {{ include.type }}:
{% include gallery.md data = include.site_data %}