Re: Pass Liquid variables to Javascript

How can I pass Liquid variables to Javascript in transaction objects?

svargas
Visitor
2 0 0

Hi everyone, I'm trying to pass some Liquid variables inside transaction object from order object, how can I do it? Something like that:

 

{% for transaction in order.transactions %}
    	let transaction_amount = {{ transaction.amount }};
       let transaction_gateway {{ transaction.gateway }}
{% endfor %}

 

  

Thanks in advance.

Replies 2 (2)

JoesIdeas
Shopify Partner
2411 222 644

Yes, like that. Although if you're looping through transactions, rather than redefine the JS variable each time, I would push them into an array of objects ( let transactions = []; ).

Note: You're missing a semicolon after the 2nd variable declaration.

Note 2: I would make the transaction amount a string, just in case you get some unexpected data, otherwise your script will break. ( let transaction_amount = "{{ transaction.amount }}"; )

• Creator of Order Automator [auto tag, fulfill, connect FBA, order jobs]
• Co-Creator of Product Automator [suite of features for products / collections]
• Shopify developer for 10+ years, store owner for 7 years
• Blog: Shopify Tips, Guides, and Automation Tools
huykon225
Shopify Partner
5 0 0

Hi, Are there any way to directly pass 

order.transactions

 to javasript then loop at js side?