Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T08:44:44.470Z
Answers.LastActivityDate: 2014-06-27T08:44:44.470Z
Answers.LastEditDate: 2023-11-17T20:33:26.840Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-29T17:00:23.347Z
Answers.LastActivityDate: 2014-06-29T17:00:23.347Z
Answers.UserDisplayName: Marion Newlevant
Body: <p>Is there a tuple data structure in Twig? If there is, how do you create one?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-27T08:37:23.307Z
Comments.Text: Do you mean tuple or ternary operator (https://en.wikipedia.org/wiki/%3F:)?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-27T08:38:16.660Z
Comments.Text: @Brad I mean tuple (first :) )
Comments.UserDisplayName: nicael
Tags: <templating>
Title: Do tuples exist in twig? If so, how can I create one?
ThreadText: # 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**: @username_1 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](http://twig.sensiolabs.org/doc/filters/merge.html) is very useful for constructing arrays and objects:
  
  ```
  {% set a = a | merge(['c']) %}
  {% set o = o | merge({'third': 'c'}) %}
  
  ```
  
  
  ---
  
  