Ad

How Do You Pass Site.data To Includes Within Includes In Jekyll?

- 1 answer

I have a snippet of code I include whenever I need to display a gallery.

<!-- _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}

I can pass site.data to populate the gallery.

{% include gallery.md data = site.data.index.themes %}

I have a template page which needs to display a gallery. I want to pass in site.data as well.

<!-- _includes/create-new.md -->

Create a new {{include.type}}:

{% include gallery.md data = {{include.site_data}} %}

But when I try to pass in site.data to the template page, I get an error.

{% include create-new.md type = "layout" site_data = site.data.index.layouts %}

How do you pass site.data to includes within includes?

Ad

Answer

Simply pass it like any other data irrespective of whether nested within another include tag:

<!-- _includes/create-new.md -->

Create a new {{ include.type }}:

{% include gallery.md data = include.site_data %}
Ad
source: stackoverflow.com
Ad