Answers.Body: <p>I see three problems here.</p>
  
  <p>One of them is the <code>-</code> in <code>membership-type</code>. <code>plandata.membership-type</code> does not mean the membership-type field of plandata, but more something like <code>(plandata.membership) minus (type)</code>. So you will either want to use <code>membershipType</code> or <code>membership_type</code>, or the less readable twig <a href="https://twig.symfony.com/doc/2.x/functions/attribute.html" rel="nofollow noreferrer">attribute</a> function: <code>attribute(plandata, 'membership-type')</code>.</p>
  
  <p>The second problem is that the twig <a href="https://twig.symfony.com/doc/2.x/filters/merge.html" rel="nofollow noreferrer">merge</a> filter operates on arrays, and you are passing it a string. This won't work: <code>|merge(amenity.title)</code>, this will: <code>|merge([amenity.title])</code></p>
  
  <p>The third problem is that the twig <a href="https://twig.symfony.com/doc/2.x/tags/set.html" rel="nofollow noreferrer">set</a> assigns values to variables, and <code>plandata.membershipType.items</code> is not a variable. The only way (in twig) to "assign" to a field of an array is with the <a href="https://twig.symfony.com/doc/2.x/filters/merge.html" rel="nofollow noreferrer">merge</a> filter. So you will need something like this:</p>
  
  <pre><code>{# create your amenityTitles array #}
  {% set amenityTitles = [] %}
  {% for amenity in entry.availableAmenities %}
    {% set amenityTitles = amenityTitles|merge([amenity.title]) %}
  {% endfor %}
  
  {# merge those amenityTitles with membershipType (somehow preexisting) #}
  {% set membershipType = membershipType | merge({items: amenityTitles})}
  
  {# merge that membershipType with plandata #}
  {% set plandata = plandata | merge({membershipType: membershipType}) %}
  </code></pre>
  
  <p>If you can figure out a less deeply nested structure than that <code>plandata</code> you will probably be happier given the limitations of twig.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-21T20:02:19.180Z
Answers.Text: Well here's what I'm trying to do. This is an existing site I just got assigned to work on not knowing anything about Craft or twig
  
  There are 4 entries, a main "Membership" page that then has a list of amenities assigned to it. Then 3 entries that are the 3 different membership descriptions, each of these entries has amenities assigned to them. I am attempting to build a comparison chart with the main page in column 1, then checkboxes for matching amenities for the 3 membership columns. I figured iterating through the amenities and add them to arrays to kick them out would be best. Opinion?
Answers.UserDisplayName: user2040962
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-21T20:27:09.343Z
Answers.Text: Maybe just iterating through the amenities and kick them out, or iterate through them and use `{% set something %} ... {% endset %}` to capture the html and then `{{something}}` later to display it. You can create complex datastructures they way you are trying to in twig, but it is a total pain in the ass.
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-20T23:51:38.383Z
Answers.LastActivityDate: 2018-02-20T23:51:38.383Z
Answers.UserDisplayName: Marion Newlevant
Body: <p>I'm trying to build an array of values from 4 entries so I can lay them out in a comparison chart. I figured the best way to do this would be to add all of the values to a nested array. So I've set this up...</p>
  
  <pre><code>{% set plandata = {
          'membership-type' : {
              'title' : 'Membership Type',
              'url' : '',
              'price' : '',
              'items' : []
          }
      }
   %}
  </code></pre>
  
  <p>then I'm iterating through a field and trying to add them to the items portion like so...</p>
  
  <pre><code>{% for amenity in entry.availableAmenities %}
      {% set plandata.membership-type.items = plandata.membership-type.items|merge(amenity.title) %}
  {% endfor %}
  </code></pre>
  
  <p>However I am getting a Template Error:  Unexpected token "punctuation" of value "." ("end of statement block" expected).</p>
  
  <p>Can anyone give me any insight as to what I'm doing wrong?</p>
  
Tags: <templating>
Title: Unexpected token "punctuation" of value "." ("end of statement block" expected)
ThreadText: # Unexpected token "punctuation" of value "." ("end of statement block" expected)
  
  (Asked by: username_0 on 2018-02-20)
  
  I'm trying to build an array of values from 4 entries so I can lay them out in a comparison chart. I figured the best way to do this would be to add all of the values to a nested array. So I've set this up...
  
  ```
  {% set plandata = {
          'membership-type' : {
              'title' : 'Membership Type',
              'url' : '',
              'price' : '',
              'items' : []
          }
      }
   %}
  
  ```
  
  then I'm iterating through a field and trying to add them to the items portion like so...
  
  ```
  {% for amenity in entry.availableAmenities %}
      {% set plandata.membership-type.items = plandata.membership-type.items|merge(amenity.title) %}
  {% endfor %}
  
  ```
  
  However I am getting a Template Error: Unexpected token "punctuation" of value "." ("end of statement block" expected).
  
  Can anyone give me any insight as to what I'm doing wrong?
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-02-20. Score: 4
  
  I see three problems here.
  
  One of them is the `-` in `membership-type`. `plandata.membership-type` does not mean the membership-type field of plandata, but more something like `(plandata.membership) minus (type)`. So you will either want to use `membershipType` or `membership_type`, or the less readable twig [attribute](https://twig.symfony.com/doc/2.x/functions/attribute.html) function: `attribute(plandata, 'membership-type')`.
  
  The second problem is that the twig [merge](https://twig.symfony.com/doc/2.x/filters/merge.html) filter operates on arrays, and you are passing it a string. This won't work: `|merge(amenity.title)`, this will: `|merge([amenity.title])`
  
  The third problem is that the twig [set](https://twig.symfony.com/doc/2.x/tags/set.html) assigns values to variables, and `plandata.membershipType.items` is not a variable. The only way (in twig) to "assign" to a field of an array is with the [merge](https://twig.symfony.com/doc/2.x/filters/merge.html) filter. So you will need something like this:
  
  ```
  {# create your amenityTitles array #}
  {% set amenityTitles = [] %}
  {% for amenity in entry.availableAmenities %}
    {% set amenityTitles = amenityTitles|merge([amenity.title]) %}
  {% endfor %}
  
  {# merge those amenityTitles with membershipType (somehow preexisting) #}
  {% set membershipType = membershipType | merge({items: amenityTitles})}
  
  {# merge that membershipType with plandata #}
  {% set plandata = plandata | merge({membershipType: membershipType}) %}
  
  ```
  
  If you can figure out a less deeply nested structure than that `plandata` you will probably be happier given the limitations of twig.
  
  > **Comments:**
  > **username_0**: Well here's what I'm trying to do. This is an existing site I just got assigned to work on not knowing anything about Craft or twig  There are 4 entries, a main "Membership" page that then has a list of amenities assigned to it. Then 3 entries that are the 3 different membership descriptions, each of these entries has amenities assigned to them. I am attempting to build a comparison chart with the main page in column 1, then checkboxes for matching amenities for the 3 membership columns. I figured iterating through the amenities and add them to arrays to kick them out would be best. Opinion?  
  > **username_1**: Maybe just iterating through the amenities and kick them out, or iterate through them and use `{% set something %} ... {% endset %}` to capture the html and then `{{something}}` later to display it. You can create complex datastructures they way you are trying to in twig, but it is a total pain in the ass.  
  
  ---
  
  