Answers.Body: <p>I know three ways:</p>
  <ul>
  <li><p><strong>Using <code>format()</code> (look for <a href="https://www.php.net/manual/en/function.sprintf.php" rel="nofollow noreferrer">type specifiers</a>)</strong></p>
  <pre><code> {% set string = &quot;There is an %s.&quot;|format(&quot;apple&quot;) %}
  </code></pre>
  </li>
  <li><p><strong>Using string interpolation (assuming that <code>apple=&quot;apple&quot;</code>)</strong></p>
  <pre><code> {% set string = &quot;There is an #{apple}.&quot; %}
  </code></pre>
  </li>
  <li><p><strong>Using string concatenation (assuming that <code>apple=&quot;apple&quot;</code>)</strong></p>
  <pre><code> {% set string = &quot;There is an &quot; ~ apple %}
  </code></pre>
  </li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-18T02:05:29.890Z
Answers.Text: i recommend string interpolation become the informal standard IMHO.
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-14T21:39:40.937Z
Answers.LastActivityDate: 2014-06-14T21:39:40.937Z
Answers.LastEditDate: 2023-11-17T20:15:17.737Z
Answers.UserDisplayName: nicael
Answers.Body: <p>If you‘ve got a multi-lingual site (or even if you don’t), you can pass variables into strings with the <a href="http://buildwithcraft.com/docs/templating/filters#translate-or-t"><code>|t</code> filter</a>:</p>
  
  <pre><code>{{ "Welcome back, {name}"|t( {'name': currentUser.name} ) }}
  </code></pre>
  
  <p>(See <a href="http://buildwithcraft.com/help/static-translations">http://buildwithcraft.com/help/static-translations</a> for details on how you can use the <code>|t</code> filter to translate your text.)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-14T22:04:24.530Z
Answers.LastActivityDate: 2014-06-14T22:04:24.530Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>How can I incorporate a variable into a string, so that the result is a longer string that includes the contents of a given variable?</p>
  
  <p>For example, I have a variable called <code>apple</code> and its value is "Arlington Pippin" (it's a <a href="http://www.orangepippin.com/apples/arlington-pippin" rel="noreferrer">type of apple</a>). I'd like to end up with a phrase that reads:</p>
  
  <blockquote>
    <p>There is an Arlington Pippin.</p>
  </blockquote>
  
  <p>How could I accomplish this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-18T19:56:35.930Z
Comments.Text: Yep, I like apples.
Comments.UserDisplayName: nicael
Tags: <templating><string><variable><concatenation>
Title: How can I incorporate a variable into a string?
ThreadText: # How can I incorporate a variable into a string?
  
  (Asked by: username_0 on 2014-06-14)
  
  How can I incorporate a variable into a string, so that the result is a longer string that includes the contents of a given variable?
  
  For example, I have a variable called `apple` and its value is "Arlington Pippin" (it's a [type of apple](http://www.orangepippin.com/apples/arlington-pippin)). I'd like to end up with a phrase that reads:
  
  > There is an Arlington Pippin.
  
  How could I accomplish this?
  
  **Tags:** templating, string, variable, concatenation
  
  > **Comments:**
  > **username_0**: Yep, I like apples.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-06-14. Score: 18 | Accepted answer
  
  If you‘ve got a multi-lingual site (or even if you don’t), you can pass variables into strings with the [`|t` filter](http://buildwithcraft.com/docs/templating/filters#translate-or-t):
  
  ```
  {{ "Welcome back, {name}"|t( {'name': currentUser.name} ) }}
  
  ```
  
  (See <http://buildwithcraft.com/help/static-translations> for details on how you can use the `|t` filter to translate your text.)
  
  
  ---
  
  ### Answer by username_0 on 2014-06-14. Score: 18
  
  I know three ways:
  
  * **Using `format()` (look for [type specifiers](https://www.php.net/manual/en/function.sprintf.php))**
  
    ```
     {% set string = "There is an %s."|format("apple") %}
  
    ```
  * **Using string interpolation (assuming that `apple="apple"`)**
  
    ```
     {% set string = "There is an #{apple}." %}
  
    ```
  * **Using string concatenation (assuming that `apple="apple"`)**
  
    ```
     {% set string = "There is an " ~ apple %}
  
    ```
  
  > **Comments:**
  > **username_1**: i recommend string interpolation become the informal standard IMHO.  
  
  ---
  
  