Answers.Body: <pre class="lang-TWIG prettyprint-override"><code>{# set test variable, to make your code work #}
  {% set block = {imageWidth: 300} %}
  
  {# the real output #}
  &lt;img{{ block.imageWidth|length ? (' width="' ~ block.imageWidth~ 'px"')|raw }} /&gt;
  </code></pre>
  
  <p>Works for me</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T08:40:10.327Z
Answers.Text: Ah I was missing the bracket, thank you!
Answers.UserDisplayName: fxfuture
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T08:34:55.920Z
Answers.LastActivityDate: 2019-03-22T08:34:55.920Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I have the following code:</p>
  
  <pre><code>&lt;img{{ block.imageWidth|length ? ' width="' ~ block.imageWidth ~ 'px"' }} /&gt;
  </code></pre>
  
  <p>If imageWidth is specified as 120, it should output:</p>
  
  <pre><code>&lt;img width="120px" /&gt;
  </code></pre>
  
  <p>However it is outputting this:</p>
  
  <pre><code>&lt;img width=&amp;quot;120px&amp;quot; /&gt;
  </code></pre>
  
  <p>I've tried using |raw but that doesn't work.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>
  
Tags: <templating><twigextension>
Title: Output raw html from if statement and combining strings?
ThreadText: # Output raw html from if statement and combining strings?
  
  (Asked by: username_0 on 2019-03-22)
  
  I have the following code:
  
  ```
  <img{{ block.imageWidth|length ? ' width="' ~ block.imageWidth ~ 'px"' }} />
  
  ```
  
  If imageWidth is specified as 120, it should output:
  
  ```
  <img width="120px" />
  
  ```
  
  However it is outputting this:
  
  ```
  <img width=&quot;120px&quot; />
  
  ```
  
  I've tried using |raw but that doesn't work.
  
  Any ideas?
  
  Thanks
  
  **Tags:** templating, twigextension
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-22. Score: 2 | Accepted answer
  
  ```TWIG
  {# set test variable, to make your code work #}
  {% set block = {imageWidth: 300} %}
  
  {# the real output #}
  <img{{ block.imageWidth|length ? (' width="' ~ block.imageWidth~ 'px"')|raw }} />
  
  ```
  
  Works for me
  
  > **Comments:**
  > **username_0**: Ah I was missing the bracket, thank you!  
  
  ---
  
  