skip to Main Content

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


  1. Try using something like this.

     const customer = {{ customer | json}}
     console.log(customer)
    
    Login or Signup to reply.
  2. 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 the json filter in liquid, which converts the object into a JSON string.

    <script>
      const customerJson = '{{ customer | json }}';
      const customer = JSON.parse(customerJson);
      console.log(customer);
    </script>
    

    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()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search