Answers.Body: <p>I have a <a href="https://github.com/carlcs/craft-helpers" rel="nofollow noreferrer">Craft Helpers</a> plugin on GitHub, which has a <code>htmlEntityDecode</code> Twig filter.</p>
  
  <pre><code>{{ value|htmlEntityDecode}}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-27T12:44:22.063Z
Answers.Text: Thanks,
  
  htmlEntityDecode did the trick.
  
  Didn't seem to work with the striptags filter by the way.
Answers.UserDisplayName: S. Connolly22
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-27T12:44:55.650Z
Answers.Text: I up-voted but it wont display as I'm a noob.
Answers.UserDisplayName: S. Connolly22
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-27T17:42:27.120Z
Answers.Text: Sorry, should have made clear that `striptags` would further get rid of HTML tags after you converted all your HTML entities. Seems like you have non, as I could have already guessed from your question. Will get rid of it in the answer. Oh and thanks for the up-vote anyway :)
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-27T12:16:45.870Z
Answers.LastActivityDate: 2017-01-27T17:42:40.153Z
Answers.LastEditDate: 2017-01-27T17:42:40.153Z
Answers.UserDisplayName: carlcs
Body: <p>Apologies if this has been asked before, I can only find questions dealing with the reverse scenario (i.e. replacing special characters with html entities)</p>
  
  <p>I need to output special characters as part of a JavaScript array using Craft. Currently the values are output with all special characters replaced by their html equivalent. (e.g.: ampersands are replaced by &amp;amp )</p>
  
  <p>I have tried restoring the special characters using craft replace but without success.</p>
  
  <p>The following code works to replace text, but does not, for example, replace &amp;amp with &amp;, or rather perhaps it does not distinguish these values as distinct.</p>
  
  <pre><code>&lt;script&gt;
  
      var myVariable = [{% for value in myArray %}"{{ value|replace('raw-html-entity', 'special-character') }}"{%- if not loop.last -%},{% endif %}{% endfor %}];
  
  &lt;/script&gt;
  </code></pre>
  
  <p>This code is being used for an array which is used for jQuery autocomplete values, so raw html is not appropriate.</p>
  
  <p>Any suggestions appreciated.</p>
  
Tags: <templating><javascript><array><replace>
Title: How to replace a html entity within script tags using Craft replace
ThreadText: # How to replace a html entity within script tags using Craft replace
  
  (Asked by: username_0 on 2017-01-27)
  
  Apologies if this has been asked before, I can only find questions dealing with the reverse scenario (i.e. replacing special characters with html entities)
  
  I need to output special characters as part of a JavaScript array using Craft. Currently the values are output with all special characters replaced by their html equivalent. (e.g.: ampersands are replaced by &amp )
  
  I have tried restoring the special characters using craft replace but without success.
  
  The following code works to replace text, but does not, for example, replace &amp with &, or rather perhaps it does not distinguish these values as distinct.
  
  ```
  <script>
  
      var myVariable = [{% for value in myArray %}"{{ value|replace('raw-html-entity', 'special-character') }}"{%- if not loop.last -%},{% endif %}{% endfor %}];
  
  </script>
  
  ```
  
  This code is being used for an array which is used for jQuery autocomplete values, so raw html is not appropriate.
  
  Any suggestions appreciated.
  
  **Tags:** templating, javascript, array, replace
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-01-27. Score: 2 | Accepted answer
  
  I have a [Craft Helpers](https://github.com/username_1/craft-helpers) plugin on GitHub, which has a `htmlEntityDecode` Twig filter.
  
  ```
  {{ value|htmlEntityDecode}}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks,  htmlEntityDecode did the trick.  Didn't seem to work with the striptags filter by the way.  
  > **username_0**: I up-voted but it wont display as I'm a noob.  
  > **username_1**: Sorry, should have made clear that `striptags` would further get rid of HTML tags after you converted all your HTML entities. Seems like you have non, as I could have already guessed from your question. Will get rid of it in the answer. Oh and thanks for the up-vote anyway :)  
  
  ---
  
  