<p>None that I'm aware of.  Since Twig ultimately gets compiled down to PHP and PHP doesn't have first-class citizen support for tuples, you're limited there.  You can quasi-fake them with <a href="https://www.php.net/manual/en/language.types.array.php" rel="nofollow noreferrer">arrays</a> and the <a href="https://www.php.net/list" rel="nofollow noreferrer">list</a> function, but I don't think there is a Twig equivalent for list.</p>

CC BY-SA 3.0
2014-06-27T08:44:44.470Z
2014-06-27T08:44:44.470Z
2023-11-17T20:33:26.840Z
Brad Bell
<p>No tuples per se. You can use arrays:</p>

<pre><code>{% set a = ['a', 'b'] %}
{{ a[0] }}
</code></pre>

<p>You can use objects:</p>

<pre><code>{% set o = {'first': 'a', 'second': 'b'} %}
{{ o.first }} or {{ attribute(o, 'first') }}
</code></pre>

<p><a href="http://twig.sensiolabs.org/doc/filters/merge.html" rel="nofollow">merge</a> is very useful for constructing arrays and objects:</p>

<pre><code>{% set a = a | merge(['c']) %}
{% set o = o | merge({'third': 'c'}) %}
</code></pre>

CC BY-SA 3.0
2014-06-29T17:00:23.347Z
2014-06-29T17:00:23.347Z
Marion Newlevant
<p>Is there a tuple data structure in Twig? If there is, how do you create one?</p>

CC BY-SA 3.0
2014-06-27T08:37:23.307Z
Do you mean tuple or ternary operator (https://en.wikipedia.org/wiki/%3F:)?
Brad Bell
CC BY-SA 3.0
2014-06-27T08:38:16.660Z
@Brad I mean tuple (first :) )
nicael
<templating>
Do tuples exist in twig? If so, how can I create one?
# Do tuples exist in twig? If so, how can I create one?

(Asked by: username_0 on 2014-06-27)

Is there a tuple data structure in Twig? If there is, how do you create one?

**Tags:** templating
> **Comments:**
> **username_1**: Do you mean tuple or ternary operator (https://en.wikipedia.org/wiki/%3F:)?  
> **username_0**: @Brad I mean tuple (first :) )  

---

## 2 answers

### Answer by username_1 on 2014-06-27. Score: 5 | Accepted answer

None that I'm aware of. Since Twig ultimately gets compiled down to PHP and PHP doesn't have first-class citizen support for tuples, you're limited there. You can quasi-fake them with [arrays](https://www.php.net/manual/en/language.types.array.php) and the [list](https://www.php.net/list) function, but I don't think there is a Twig equivalent for list.


---

### Answer by username_2 on 2014-06-29. Score: 4

No tuples per se. You can use arrays:
{% set a = ['a', 'b'] %}
{{ a[0] }}

You can use objects:
{% set o = {'first': 'a', 'second': 'b'} %}
{{ o.first }} or {{ attribute(o, 'first') }}

merge is very useful for constructing arrays and objects:
{% set a = a | merge(['c']) %}
{% set o = o | merge({'third': 'c'}) %}


---

