Answers.Body: <p>Since Twig is server-side, and Javascript (usually) is client-side, you would need to change your code's logic so that the desired value you need inside that Twig command can be injected using javascript on the client's side.</p>
  <p>Then you could send that data back along with the rest of the submission.</p>
  <p>If you need server-side javascript, you would want to look at node.js</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-26T10:13:17.330Z
Answers.LastActivityDate: 2021-02-26T10:13:17.330Z
Answers.UserDisplayName: MisterMike
Body: <p>I am using the Enupal Stripe Payments plugin to pass line items to Stripe. The line items get passed in an array. I want to use a javascript cart to hold the items in local storage, reformat that and then send them to the twig array that will eventually be sent to Stripe.</p>
  <p>I have reformatted the JSON from local storage using javascript and can see the output in my console. How can I include that javascript inside the twig array? I have read some vague feedback about using AJAX for this but I do not fully understand how to accomplish that or if it is the correct solution for this use case.</p>
  <p>Stripe TWIG array example:</p>
  <pre><code>{% set options = {
      lineItems : MY JAVASCRIPT GOES HERE
  } %}
  </code></pre>
  
Tags: <templating><ajax><javascript>
Title: Output javascript inside twig variable
ThreadText: # Output javascript inside twig variable
  
  (Asked by: username_0 on 2021-02-25)
  
  I am using the Enupal Stripe Payments plugin to pass line items to Stripe. The line items get passed in an array. I want to use a javascript cart to hold the items in local storage, reformat that and then send them to the twig array that will eventually be sent to Stripe.
  
  I have reformatted the JSON from local storage using javascript and can see the output in my console. How can I include that javascript inside the twig array? I have read some vague feedback about using AJAX for this but I do not fully understand how to accomplish that or if it is the correct solution for this use case.
  
  Stripe TWIG array example:
  
  ```
  {% set options = {
      lineItems : MY JAVASCRIPT GOES HERE
  } %}
  
  ```
  
  **Tags:** templating, ajax, javascript
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-02-26. Score: 1
  
  Since Twig is server-side, and Javascript (usually) is client-side, you would need to change your code's logic so that the desired value you need inside that Twig command can be injected using javascript on the client's side.
  
  Then you could send that data back along with the rest of the submission.
  
  If you need server-side javascript, you would want to look at node.js
  
  
  ---
  
  