Answers.Body: <p>Another option is to use the <a href="http://twig.sensiolabs.org/doc/filters/join.html">twig join filter</a>:</p>
  
  <pre><code>{% set urlParam = [street, city, 'UT']|join(', ') %}
  </code></pre>
  
  <p><a href="http://twig.sensiolabs.org/doc/filters/join.html">join</a> concatenates the items in the sequence with the separator of your choice in between.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-25T20:58:39.443Z
Answers.Text: For things like addresses I usually use `|filter|join(', ')` so there are no repeated commas if any of the fields are null or empty.
Answers.UserDisplayName: Mike Pepper
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-26T22:29:54.410Z
Answers.Text: Thanks, Marion - that seems to make a lot more sense than my approach!
Answers.UserDisplayName: Roi Agneta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-27T19:31:44.963Z
Answers.Text: mark me correct?
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-25T18:38:23.067Z
Answers.LastActivityDate: 2014-11-25T18:38:23.067Z
Answers.UserDisplayName: Marion Newlevant
Answers.Body: <p>Figured it out!  Proper syntax is:</p>
  
  <pre><code>{% set urlParam = street ~", " ~city ~", UT"  %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-25T18:17:47.793Z
Answers.LastActivityDate: 2016-06-01T13:56:17.587Z
Answers.LastEditDate: 2016-06-01T13:56:17.587Z
Answers.UserDisplayName: Roi Agneta
Answers.Body: <p>Just wanted to add another example to this since this post help point me in the right direction.</p>
  
  <p>In my example, I am getting back a list of events from a 3rd party. All that is returned to me is the slug. But, you can see that I wanted the url to be prepended with <code>/event-results/</code>.</p>
  
  <pre><code>&lt;a href="{{ url('/evnet-results/'~event.slug) }}"&gt;{{ event.title }}&lt;/a&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-11T20:02:26.007Z
Answers.LastActivityDate: 2016-12-11T20:02:26.007Z
Answers.UserDisplayName: Damon
Body: <p>I am trying to form a url parameter (for Google Maps API) from entry field data. Basically, this is what I would like to do:</p>
  
  <pre><code>{% set street = entry.address %}
  
  {% set  city = entry.city %}
  
  {% set urlParam = street.", ".city.", UT"  %}
  </code></pre>
  
  <p>Is this possible with Twig and, if so, what is the proper syntax for concatenating multiple variables and strings?</p>
  
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-27T19:30:24.307Z
Comments.Text: Can you clarify the title to say something along the lines as to where you are try to do this, such as "in a template".
Comments.UserDisplayName: Jason McCallister
Tags: <variable>
Title: how to concatenate multiple variables and strings
ThreadText: # how to concatenate multiple variables and strings
  
  (Asked by: username_0 on 2014-11-25)
  
  I am trying to form a url parameter (for Google Maps API) from entry field data. Basically, this is what I would like to do:
  
  ```
  {% set street = entry.address %}
  
  {% set  city = entry.city %}
  
  {% set urlParam = street.", ".city.", UT"  %}
  
  ```
  
  Is this possible with Twig and, if so, what is the proper syntax for concatenating multiple variables and strings?
  
  Thanks!
  
  **Tags:** variable
  
  > **Comments:**
  > **username_1**: Can you clarify the title to say something along the lines as to where you are try to do this, such as "in a template".  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2014-11-25. Score: 9
  
  Another option is to use the [twig join filter](http://twig.sensiolabs.org/doc/filters/join.html):
  
  ```
  {% set urlParam = [street, city, 'UT']|join(', ') %}
  
  ```
  
  [join](http://twig.sensiolabs.org/doc/filters/join.html) concatenates the items in the sequence with the separator of your choice in between.
  
  > **Comments:**
  > **username_3**: For things like addresses I usually use `|filter|join(', ')` so there are no repeated commas if any of the fields are null or empty.  
  > **username_0**: Thanks, username_2 - that seems to make a lot more sense than my approach!  
  > **username_2**: mark me correct?  
  
  ---
  
  ### Answer by username_0 on 2014-11-25. Score: 8
  
  Figured it out! Proper syntax is:
  
  ```
  {% set urlParam = street ~", " ~city ~", UT"  %}
  
  ```
  
  
  ---
  
  ### Answer by username_4 on 2016-12-11. Score: 2
  
  Just wanted to add another example to this since this post help point me in the right direction.
  
  In my example, I am getting back a list of events from a 3rd party. All that is returned to me is the slug. But, you can see that I wanted the url to be prepended with `/event-results/`.
  
  ```
  <a href="{{ url('/evnet-results/'~event.slug) }}">{{ event.title }}</a>
  
  ```
  
  
  ---
  
  