# List of tuples in shortcodes

**URL:** <https://zola.discourse.group/t/list-of-tuples-in-shortcodes/267>\
**Category:** Support\
**Created:** [November 29, 2019, 8:34am UTC](https://zola.discourse.group/t/list-of-tuples-in-shortcodes/267 "2019-11-29T08:34:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![photong](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/photong/32/120_2.png) [@photong](https://zola.discourse.group/u/photong)\
**Post date:** [November 29, 2019, 8:34am UTC](https://zola.discourse.group/t/list-of-tuples-in-shortcodes/267/1 "2019-11-29T08:34:06Z")

</div>

Sometimes it’s useful to give a list to a shortcode. For example:  
{{ draw\_gallery(images=[“img1.jpg”, “img2.jpg”, “img3.jpg”]) }}

In jinja2, macros can take a list of tuples. For example (in a template):  
{% draw\_gallery([(“img1.jpg”, “small”), (“img2.jpg”, “big”), (“img3.jpg”, “big”)]) %}

Then in the macro:  
{% for image, size in images %}

This doesn’t seem to work with Tera. The Tera docs give the example:

{% for key, value in products %}  
{{loop.index}}. {{product.name}}  
{% endfor %}

but “key” and “value” are not used in the loop and it’s not clear how they are set in the template. Can a list of tuples be passed to a shortcode in Zola? If so, how? Thanks.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [November 29, 2019, 10:24am UTC](https://zola.discourse.group/t/list-of-tuples-in-shortcodes/267/2 "2019-11-29T10:24:52Z")

</div>

Tuples don’t exist in Tera. The `for key, value` is used when iterating on serde\_json Value::Object (hashmaps/structs basically).

---

<div class="post-metadata">

**Author:** ![photong](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/photong/32/120_2.png) [@photong](https://zola.discourse.group/u/photong)\
**Post date:** [November 29, 2019, 2:37pm UTC](https://zola.discourse.group/t/list-of-tuples-in-shortcodes/267/3 "2019-11-29T14:37:51Z")

</div>

Ok, thanks.

> Tuples don’t exist in Tera.

The Tera docs mention “tuple” a few times.  
“Specific members of an array or **tuple** are accessed by using …”  
“If you need to sort a list of structs or **tuples** …”  
“Returns true if the given variable can be iterated over in Tera (ie is an array/ **tuple** ).”

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [November 29, 2019, 4:12pm UTC](https://zola.discourse.group/t/list-of-tuples-in-shortcodes/267/4 "2019-11-29T16:12:23Z")

</div>

That’s because Tera uses JSON underneath. So `(something, else)` in Rust would be transformed into an array since JSON doesn’t have the concept of tuples. Maybe I should remove mentions of tuples in the Tera doc, I can see how that would be confusing.

For your macro example, it might work with nested arrays eg `{% draw_gallery([[“img1.jpg”, “small”], [“img2.jpg”, “big”], [“img3.jpg”, “big”]]) %}` but I cannot remember if nested arrays are implemented in Tera off the top of my head.

---

<div class="post-metadata">

**Author:** ![photong](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/photong/32/120_2.png) [@photong](https://zola.discourse.group/u/photong)\
**Post date:** [December 1, 2019, 10:28am UTC](https://zola.discourse.group/t/list-of-tuples-in-shortcodes/267/5 "2019-12-01T10:28:53Z")

</div>

Nested arrays do not work. I’ll use another method to accomplish this. Thanks.
