When I try to assign a liquid object, it returns a drop. Here’s my code,
<script>
const customer = '{{ customer }}'
console.log(customer)
</script>
And it returns CustomerDrop
as an output. How do I get it as an object?
When I try to assign a liquid object, it returns a drop. Here’s my code,
<script>
const customer = '{{ customer }}'
console.log(customer)
</script>
And it returns CustomerDrop
as an output. How do I get it as an object?
2
Answers
Try using something like this.
In shopify, liquid objects are converted into a special data type called
drops
which can only be used within liquid templates. To access and manipulate liquid objects in js, you need to first convert them into a valid JSON format. To do this, you can use thejson
filter in liquid, which converts the object into a JSON string.This will output the customer object as a string in JSON format, which can then be parsed into a JS object using the
JSON.parse()