Answers.Body: <p>It appears to be due to the angle brackets. Try:</p>
  
  <pre><code>&lt;script&gt;
      var homepageStandfirstAnchors = [{% for anchor in homepage.homepageStandfirstAnchors %}[{{ anchor.text }},{{ anchor.section.handle }},{{ anchor.anchorLink }}],{% endfor %}];
  &lt;/script&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-25T10:56:22.730Z
Answers.Text: DUH whoops. I'll delete this question but thanks!
Answers.UserDisplayName: Daniel
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-25T10:36:55.680Z
Answers.LastActivityDate: 2014-09-25T10:36:55.680Z
Answers.UserDisplayName: Shane Hudson
Body: <p>I think I might be missing something here but it seems twig tags aren't parsed within  tags? Is there any way they can be, e.g.:</p>
  
  <pre><code>&lt;script&gt;
  var homepageStandfirstAnchors = [&lt;% for anchor in homepage.homepageStandfirstAnchors %&gt;[{{ anchor.text }},{{ anchor.section.handle }},{{ anchor.anchorLink }}],&lt;% endfor %&gt;];
  &lt;/script&gt;
  </code></pre>
  
  <p>doesn't work as expected.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-09-25T10:56:58.670Z
Comments.Text: My bad - should have been {% not <%
Comments.UserDisplayName: Daniel
Tags: <templating><javascript>
Title: Twig templating within <script> tag
ThreadText: # Twig templating within <script> tag
  
  (Asked by: username_0 on 2014-09-25)
  
  I think I might be missing something here but it seems twig tags aren't parsed within tags? Is there any way they can be, e.g.:
  
  ```
  <script>
  var homepageStandfirstAnchors = [<% for anchor in homepage.homepageStandfirstAnchors %>[{{ anchor.text }},{{ anchor.section.handle }},{{ anchor.anchorLink }}],<% endfor %>];
  </script>
  
  ```
  
  doesn't work as expected.
  
  **Tags:** templating, javascript
  
  > **Comments:**
  > **username_0**: My bad - should have been {% not <%  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-09-25. Score: 1 | Accepted answer
  
  It appears to be due to the angle brackets. Try:
  
  ```
  <script>
      var homepageStandfirstAnchors = [{% for anchor in homepage.homepageStandfirstAnchors %}[{{ anchor.text }},{{ anchor.section.handle }},{{ anchor.anchorLink }}],{% endfor %}];
  </script>
  
  ```
  
  > **Comments:**
  > **username_0**: DUH whoops. I'll delete this question but thanks!  
  
  ---
  
  