<p>You can concatenate variables like this:</p>

<pre><code>{% set foo = 'foo' %}
{% set bar = 'bar' %}
{% set foobar = 'Hello' ~ foo ~ bar %}
{{ foobar }} #Outputs Hello foobar
</code></pre>

<p>It's explained by Brandon <a href="https://github.com/brandonkelly/TwigForDesigners/blob/master/values-expressions-and-variables.md#expressions" rel="nofollow">here</a>.</p>

CC BY-SA 3.0
2015-10-12T10:46:49.743Z
Perfect thanks! Thank you for the resource too, very helpful!
JRW
CC BY-SA 3.0
2015-10-12T10:42:13.907Z
2015-10-12T10:47:24.520Z
2015-10-12T10:47:24.520Z
Paul
<p>How can I create a variable that is a combination of two variables with text?</p>

<p>For example, I know the following is wrong but is something like this possible:</p>

<pre><code>{% set foo = 'foo' %}
{% set bar = 'bar' %}
{% set foobar = 'Hello' foo,bar %}
{{ foobar }} #Outputs Hello foobar
</code></pre>

<variable><set>
Combine variables with text to make variable
# Combine variables with text to make variable

(Asked by: username_0 on 2015-10-12)

How can I create a variable that is a combination of two variables with text?
For example, I know the following is wrong but is something like this possible:
{% set foo = 'foo' %}
{% set bar = 'bar' %}
{% set foobar = 'Hello' foo,bar %}
{{ foobar }} #Outputs Hello foobar

**Tags:** variable, set

---

## 1 answers

### Answer by username_1 on 2015-10-12. Score: 2 | Accepted answer

You can concatenate variables like this:
{% set foo = 'foo' %}
{% set bar = 'bar' %}
{% set foobar = 'Hello' ~ foo ~ bar %}
{{ foobar }} #Outputs Hello foobar

It's explained by Brandon here.

> **Comments:**
> **username_0**: Perfect thanks! Thank you for the resource too, very helpful!  

---

