<p>The main thing to remember about Twig... <strong>You never need to nest tags within other tags</strong>. So putting <code>{{ }}</code> within <code>{% %}</code> is never going to work.</p>

<p>To concatenate a string in Twig, <a href="http://twig.sensiolabs.org/doc/templates.html#expressions" rel="nofollow">use the <code>~</code> character...</a></p>

<pre><code>{% set email = "&lt;a href='mailto:" ~ contactInfo.contactEmail ~ "'&gt;" ~ contactInfo.contactEmail ~ "&lt;/a&gt;" %}
</code></pre>

CC BY-SA 3.0
2014-09-26T02:52:24.340Z
Thanks so much! Never knew about concatenation in Twig so that's great to learn you can do that. Thanks again.
markstewie
CC BY-SA 3.0
2014-09-26T02:54:11.470Z
You're very welcome!
Lindsey D
CC BY-SA 3.0
2014-09-26T02:50:50.837Z
2014-09-26T02:50:50.837Z
Lindsey D
<p>Another way to do this is to use the other <a href="http://twig.sensiolabs.org/doc/tags/set.html" rel="nofollow">set syntax</a>:</p>

<pre><code>{% set email %}
  &lt;a href="mailto:{{ contactInfo.contactEmail }}"&gt;{{ contactInfo.contactEmail }}&lt;/a&gt;
{% endset %}
</code></pre>

<p>Sometimes it is easier to read.</p>

CC BY-SA 3.0
2014-09-26T05:47:30.293Z
2014-09-26T05:47:30.293Z
Marion Newlevant
<p>I'm trying to use <a href="http://sprout.barrelstrengthdesign.com/craft-plugins/encode-email/docs/getting-started/introductio">the Encode Email plugin</a> to encode email addresses.</p>

<p>The email addresses are dynamic so I need to include the output from the database when I'm using set.</p>

<p>This is their example that doesn't use dynamic info:</p>

<pre><code>{% set email = "&lt;a href='mailto:you@example.com'&gt;Your Name&lt;/a&gt;" %}
{{ email | rot13 }}
</code></pre>

<p>And this is what I've tried that doesn't work.</p>

<pre><code>{% set email = "&lt;a href='mailto:{{ contactInfo.contactEmail }}'&gt;{{ contactInfo.contactEmail }}&lt;/a&gt;" %}
{{ email | rot13 }}
</code></pre>

<p>Is there a way to include the dynamic variables into the set statement?</p>

<templating>
Twig Templates : Include dynamic data when using set
# Twig Templates : Include dynamic data when using set

(Asked by: username_0 on 2014-09-26)

I'm trying to use the Encode Email plugin to encode email addresses.
The email addresses are dynamic so I need to include the output from the database when I'm using set.
This is their example that doesn't use dynamic info:
{% set email = "Your Name" %}
{{ email | rot13 }}

And this is what I've tried that doesn't work.
{% set email = "{{ contactInfo.contactEmail }}" %}
{{ email | rot13 }}

Is there a way to include the dynamic variables into the set statement?

**Tags:** templating


---

## 2 answers

### Answer by username_1 on 2014-09-26. Score: 4 | Accepted answer

The main thing to remember about Twig... You never need to nest tags within other tags. So putting {{ }} within {% %} is never going to work.
To concatenate a string in Twig, use the ~ character...
{% set email = "" ~ contactInfo.contactEmail ~ "" %}

> **Comments:**
> **username_0**: Thanks so much! Never knew about concatenation in Twig so that's great to learn you can do that. Thanks again.  
> **username_1**: You're very welcome!  

---

### Answer by username_2 on 2014-09-26. Score: 4

Another way to do this is to use the other set syntax:
{% set email %}
  {{ contactInfo.contactEmail }}
{% endset %}

Sometimes it is easier to read.


---

