<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>

CC BY-SA 3.0
2014-11-25T20:58:39.443Z
For things like addresses I usually use `|filter|join(', ')` so there are no repeated commas if any of the fields are null or empty.
Mike Pepper
CC BY-SA 3.0
2014-11-26T22:29:54.410Z
Thanks, Marion - that seems to make a lot more sense than my approach!
Roi Agneta
CC BY-SA 3.0
2014-11-27T19:31:44.963Z
mark me correct?
Marion Newlevant
CC BY-SA 3.0
2014-11-25T18:38:23.067Z
2014-11-25T18:38:23.067Z
Marion Newlevant
<p>Figured it out!  Proper syntax is:</p>

<pre><code>{% set urlParam = street ~", " ~city ~", UT"  %}
</code></pre>

CC BY-SA 3.0
2014-11-25T18:17:47.793Z
2016-06-01T13:56:17.587Z
2016-06-01T13:56:17.587Z
Roi Agneta
<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>

CC BY-SA 3.0
2016-12-11T20:02:26.007Z
2016-12-11T20:02:26.007Z
Damon
<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>

CC BY-SA 3.0
2014-11-27T19:30:24.307Z
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".
Jason McCallister
<variable>
how to concatenate multiple variables and strings
# 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:
{% set urlParam = [street, city, 'UT']|join(', ') %}

join 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, Marion - 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/.
{{ event.title }}


---

