Answers.Body: <p>try:</p>
  
  <pre><code>{% set params = params | merge({
      postDate:['and', '&gt;= ' ~ start.date, '&lt; ' ~ end.date]
  }) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-15T13:01:30.617Z
Answers.Text: Perfect. Thank you.
Answers.UserDisplayName: CreateSean
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-15T08:17:16.433Z
Answers.LastActivityDate: 2019-05-15T08:17:16.433Z
Answers.UserDisplayName: Oli
Body: <p>I'm attempting to merge in postDate restrictions based on the url segment. However I get twig errors with my code.</p>
  
  <p>So for a link of domain.com/news/archive/2016 I want to see all entries with a postDate in 2016.</p>
  
  <p>current code:</p>
  
  <pre><code>{% set params = { section: 'news', limit: 5 } %}
  
  {# check for annual archive in the url #}
  {% if craft.app.request.getSegment(2) == "archive" %}
      {% set year = craft.app.request.getSegment(3) %}
  
      {% set start = date( year ~ '-01-01') %} 
      {% set end = date( year ~ '-12-31') %}
  
      {% set params = params | merge({ 
        postDate(['and', "&gt;= " ~ start, "&lt; " ~ end])
       }) %}
  {% endif %}
  {# end check for annual archive #}
  </code></pre>
  
  <p>And the Error I get</p>
  
  <pre><code>A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "(" ("punctuation" expected with value ":").
  </code></pre>
  
  <p><strong>Also not working</strong>
  I tried a couple of variations - this gets no errors, but also no entries are output</p>
  
  <pre><code>{% set params = { section: 'news', limit: 5 } %}
  
  {# check for annual archive in the url #}
  {% if craft.app.request.getSegment(2) == "archive" %}
      {% set year = craft.app.request.getSegment(3) %}
  
      {% set start = date( year ~ '-01-01') %} 
      {% set end = date( year ~ '-12-31') %}
  
      {% set params = params | merge({ 
        postDate: "['and', '&gt;= ' ~ start, '&lt; ' ~ end]",
       }) %}
  {% endif %}
  </code></pre>
  
Tags: <templating><entries><merge>
Title: Merging params PostDate limits errors
ThreadText: # Merging params PostDate limits errors
  
  (Asked by: username_0 on 2019-05-14)
  
  I'm attempting to merge in postDate restrictions based on the url segment. However I get twig errors with my code.
  
  So for a link of domain.com/news/archive/2016 I want to see all entries with a postDate in 2016.
  
  current code:
  
  ```
  {% set params = { section: 'news', limit: 5 } %}
  
  {# check for annual archive in the url #}
  {% if craft.app.request.getSegment(2) == "archive" %}
      {% set year = craft.app.request.getSegment(3) %}
  
      {% set start = date( year ~ '-01-01') %} 
      {% set end = date( year ~ '-12-31') %}
  
      {% set params = params | merge({ 
        postDate(['and', ">= " ~ start, "< " ~ end])
       }) %}
  {% endif %}
  {# end check for annual archive #}
  
  ```
  
  And the Error I get
  
  ```
  A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "(" ("punctuation" expected with value ":").
  
  ```
  
  **Also not working**
  I tried a couple of variations - this gets no errors, but also no entries are output
  
  ```
  {% set params = { section: 'news', limit: 5 } %}
  
  {# check for annual archive in the url #}
  {% if craft.app.request.getSegment(2) == "archive" %}
      {% set year = craft.app.request.getSegment(3) %}
  
      {% set start = date( year ~ '-01-01') %} 
      {% set end = date( year ~ '-12-31') %}
  
      {% set params = params | merge({ 
        postDate: "['and', '>= ' ~ start, '< ' ~ end]",
       }) %}
  {% endif %}
  
  ```
  
  **Tags:** templating, entries, merge
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-15. Score: 2 | Accepted answer
  
  try:
  
  ```
  {% set params = params | merge({
      postDate:['and', '>= ' ~ start.date, '< ' ~ end.date]
  }) %}
  
  ```
  
  > **Comments:**
  > **username_0**: Perfect. Thank you.  
  
  ---
  
  