I’m new to Liquid and I’m trying to create a Mechanic script in Shopify to loop through all my orders and check each SKU. This is what I came up with:
{% for line_item in order.line_items %}
{% if line_item.sku %}
{{ line_item.sku }}
{% capture sku %}
On the third line, I was expecting to see it print an order’s SKU, which should look like this: 1xSAMPLE1+2xSAMPLE2. It, however, showed me this error:
lexical error: invalid char in json text.
1xS
(right here) ------^
Typically, this comes down to a stray comma, or some other character that makes for invalid JSON.
Context (lines 2-5 of rendered JSON):
As I understand it, Mechanic (or Liquid) only wants to print JSON values. How do I view my variables while running the Mechanic script?
ah. I just read the docs on capture. Will update the code, thanks for pointing that out. That was not what I intended. I thought how capture worked is it assigns the result of the previous line to the variable in the next line inside the capture tag
@pdarceno Did fixing the capture tag syntax fix the error?
With liquid whenever possibly try to use the assign tag instead of capture to cut down on edge issues like whitespace, newlines , improve readability and as you’ve found avoid tag wrapping mistakes either from hand coding or autocompletion,etc.
For mechanic specific issues also try the mechanic partner slack channel first since mechanic-liquid and it’s other features is a smaller audience on the forums vs shopify-liquid.
Keep in mind that apps mechanics-liquid is not the same as shopify-liquid for the platform. They have overlap of some basics but are different flavors|implementations of the liquid template engine.
Also be aware some the differences are features for working with arrays in saner manner not needing the “| split:‘,’” workaround required in shopify templates. And that you can make objects and hashes as well.