Answers.Body: <p>That's what you are after:</p>
  
  <pre><code>startDateTime : 'and', '&gt;= ' ~ now, '&lt;= ' ~ now | date_modify('+5 days')
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-22T08:00:02.283Z
Answers.Text: For some reason this is throwing an error for me. It doesn't seem to like the extra commas ('and, ..., ...') used within the params object declaration {}. How did you get this to work?
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-22T17:56:54.050Z
Answers.Text: @DouglasMcDonald what you need to the right of the `:` is a string: `'and, >= '~now~', <= '~(now|date_modify('+5 days'))`
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-25T03:06:34.297Z
Answers.Text: @MarionNewlevant for some reason it didn't like to parse the string using the | merge filter. I think maybe something in today's update may have addressed this. Regardless I ended up using an array which seemed to do the trick. [ "and", ">= " ~ from | date('U'), "< " ~ to | date('U') ]
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T13:26:31.743Z
Answers.Text: Is there more info about this in the docs? This is super helpful to learn.
Answers.UserDisplayName: John D Wells
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T13:42:13.983Z
Answers.Text: Sorry, didn't find anything in the docs. I learned about that technique in a g+ thread the other day. The only additional info I can give you is that you can also combine operators with 'or'.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T15:56:37.537Z
Answers.Text: How would you use an "and" with an "or" for example: ( >= now and <= now + 5 days ) || ( >= now + 10 days and <= now + 15 days ) ?
Answers.UserDisplayName: Steve Adams
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T11:23:33.870Z
Answers.LastActivityDate: 2014-06-12T11:23:33.870Z
Answers.UserDisplayName: carlcs
Body: <p>I'm looking for documentation on how to use operators in hashes in Twig. Someone mentioned this in the Google+ support group the other day and I was unable to find any docs or examples.</p>
  
  <pre><code>{% set eventParams = {
    section       : 'events',
    order         : 'startDateTime asc',
    startDateTime : '&gt;= '~now
  } %}
  </code></pre>
  
  <p>If I wanted the startDateTime hash to use a range of dates, say ( <code>&gt;= now</code> and <code>&lt;= now + 5 days</code> ) how would I specify that in the startDateTime hash?</p>
  
  <p>Is this a hash syntax that is specific to Twig?</p>
  
Tags: <hash><templating>
Title: How can I use operators within Twig hashes?
ThreadText: # How can I use operators within Twig hashes?
  
  (Asked by: username_0 on 2014-06-12)
  
  I'm looking for documentation on how to use operators in hashes in Twig. Someone mentioned this in the Google+ support group the other day and I was unable to find any docs or examples.
  
  ```
  {% set eventParams = {
    section       : 'events',
    order         : 'startDateTime asc',
    startDateTime : '>= '~now
  } %}
  
  ```
  
  If I wanted the startDateTime hash to use a range of dates, say ( `>= now` and `<= now + 5 days` ) how would I specify that in the startDateTime hash?
  
  Is this a hash syntax that is specific to Twig?
  
  **Tags:** hash, templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-12. Score: 11 | Accepted answer
  
  That's what you are after:
  
  ```
  startDateTime : 'and', '>= ' ~ now, '<= ' ~ now | date_modify('+5 days')
  
  ```
  
  > **Comments:**
  > **username_4**: Is there more info about this in the docs? This is super helpful to learn.  
  > **username_1**: Sorry, didn't find anything in the docs. I learned about that technique in a g+ thread the other day. The only additional info I can give you is that you can also combine operators with 'or'.  
  > **username_0**: How would you use an "and" with an "or" for example: ( >= now and <= now + 5 days ) || ( >= now + 10 days and <= now + 15 days ) ?  
  > **username_2**: For some reason this is throwing an error for me. It doesn't seem to like the extra commas ('and, ..., ...') used within the params object declaration {}. How did you get this to work?  
  > **username_3**: @username_2 what you need to the right of the `:` is a string: `'and, >= '~now~', <= '~(now|date_modify('+5 days'))`  
  > **username_2**: @username_3 for some reason it didn't like to parse the string using the | merge filter. I think maybe something in today's update may have addressed this. Regardless I ended up using an array which seemed to do the trick. [ "and", ">= " ~ from | date('U'), "< " ~ to | date('U') ]  
  
  ---
  
  