I have a Shopify store using the new Dawn template, which includes JSON templates. I’d like to add a textarea where customers can write text they’d like to have engraved on their items, which seems to be a common usecase.
I added a “Custom liquid” element to my product page and inserted a form field generated by the Shopify UI Element generator. However, I noticed that this field isn’t inside the element, so it wasn’t getting included in the order.
I looked at the source of the product page, and noticed the form has an ID like product-form-template–14290791497780__main. I copied that ID and set it as the form attribute on my textbox, and now everything’s working but it feels fragile. I don’t know how this ID is generated - it looks like the unix timestamp of when the template was created? So if I ever modify this template, I’ll need to update it? Is there a way to refer to this ID from the liquid template without having to hard code the ID?
Here’s my product.json template
The important part is this bit
"728d07ea-3e35-4ab1-bed3-ac9d9f35875c": {
"type": "custom_liquid",
"settings": {
"custom_liquid": "
\n
\n
As far as I can tell, the "buy_buttons" block is what creates the submission form for the product. My custom liquid block includes form=\"product-form-template--14302685823028__main\", which is the ID of the form I got by viewing source on the page. I'd like to replace that with some liquid expression, like {{ product_form.id }} or whatever, but I don't know how to refer to other blocks in the JSON template from a custom liquid block.