The Oddler
The Oddler

Reputation: 6698

Jekyll/liquid list parameter?

I wanted to create a simply include which simplifies creating a carousel. So I was looking for the syntax to give a list of image urls as a parameter. However I couldn't find anything about this.

{% include carousel.html images=WHAT HERE? %}

Upvotes: 0

Views: 425

Answers (1)

GeorgeButter
GeorgeButter

Reputation: 2591

You can create a list as a string then convert it into an array inside your snippet. This is the way I would do it.

{% assign urls = 'url1.jpg,url2.jpg,url3.jpg' %}

{% include carousel.html images=urls %}

Of course this is the same as:

{% include carousel.html images='url1.jpg,url2.jpg,url3.jpg' %}

carousel.html

{% assign images = include.images | split: ',' %}
{% for image in images %}
   {{ image }}
{% endfor %}

Upvotes: 2

Related Questions