title: Twig merge multiple things in an array
body: <p>I'm trying to create an array with dates in it for an order system. Those dates corresponds with days that the shop can't deliver. </p>
  
  <p>I'm having trouble to create that array since values are strings and that keeps getting producing an error with the <code>merge</code> filter. 
  <strong>I have only access to the frontend of the shop so I can't create custom functions whatsover.</strong> </p>
  
  <p>The end result need to be an array with all dates in it so I can use that as javascript array, like so:</p>
  
  <pre><code>var closed = [
    {{ closedDates }} // ["01-01-2018", "02-01-2018", etc...]      
  ];
  </code></pre>
  
  <p>So what I have is this:</p>
  
  <p>1) Webshop fills in the single days they are closed and perhaps a range of days.
     That are three variables like:</p>
  
  <pre><code> {{ closedDays }} {# produces eg 01-01-2018, 02-01-2018, 03-01-2018 { it's dd-mm-yy #} 
   {{ date_range_start }} {# produces eg. 10-01-2018 #}
   {{ date_range_end }} {# produces eg. 20-01-2018 #}
  </code></pre>
  
  <p>2) So what I did is this:</p>
  
  <pre><code> {% set closedDates = [] %}    
  
  
    {% if theme.closedDays %}
      {% set foo = theme.closedDays %}
      {% for i in foo | slice(0, 5) %}
         {% set closedDates = closedDates | merge(i) %}
      {% endfor %}
  
    {% endif %}
  
    {% if theme.date_range_start and theme.date_range_end  %}
       {% set start_date = theme.date_range_start  %}
       {% set end_date = theme.date_range_end %}
  
       {# below function lists all days between start and end date #}
       {% for weekRange in range(start_date|date('U'), end_date|date('U'), 86400 ) %}
          {% set closedDates = closedDates | merge(weekRange | date('d-m-Y')) %} 
       {% endfor %}
    {% endif %}
  </code></pre>
  
  <p>When I do it like above I get an error saying <code>The merge filter only works with arrays or hashes;</code>. But how do you create an array then with those values? That's only done with <code>merge</code> right?!</p>
  
  <p>Any help greatly appreciated. </p>