Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-26T02:52:24.340Z
Answers.Text: Thanks so much! Never knew about concatenation in Twig so that's great to learn you can do that. Thanks again.
Answers.UserDisplayName: markstewie
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-26T02:54:11.470Z
Answers.Text: You're very welcome!
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-26T02:50:50.837Z
Answers.LastActivityDate: 2014-09-26T02:50:50.837Z
Answers.UserDisplayName: Lindsey D
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-26T05:47:30.293Z
Answers.LastActivityDate: 2014-09-26T05:47:30.293Z
Answers.UserDisplayName: Marion Newlevant
Body: <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>
  
Tags: <templating>
Title: Twig Templates : Include dynamic data when using set
ThreadText: # 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](http://sprout.barrelstrengthdesign.com/craft-plugins/encode-email/docs/getting-started/introductio) 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 = "<a href='mailto:you@example.com'>Your Name</a>" %}
  {{ email | rot13 }}
  
  ```
  
  And this is what I've tried that doesn't work.
  
  ```
  {% set email = "<a href='mailto:{{ contactInfo.contactEmail }}'>{{ contactInfo.contactEmail }}</a>" %}
  {{ 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...](http://twig.sensiolabs.org/doc/templates.html#expressions)
  
  ```
  {% set email = "<a href='mailto:" ~ contactInfo.contactEmail ~ "'>" ~ contactInfo.contactEmail ~ "</a>" %}
  
  ```
  
  > **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](http://twig.sensiolabs.org/doc/tags/set.html):
  
  ```
  {% set email %}
    <a href="mailto:{{ contactInfo.contactEmail }}">{{ contactInfo.contactEmail }}</a>
  {% endset %}
  
  ```
  
  Sometimes it is easier to read.
  
  
  ---
  
  