theme-tools icon indicating copy to clipboard operation
theme-tools copied to clipboard

Introduce snippet dependency annotation

Open karreiro opened this issue 2 years ago • 0 comments

Are you seeking a solution to a specific problem? Let's delve into it.

Some Shopify Liquid assets, like snippets, depend on variables that are not defined in the global scope. Instead, these variables find their definition within the parent template.

This is about supporting a type annotation to declare those variables, so the UndefinedObject may rely on those annotations to understand the variables available in runtime for a given template. By doing so, we hope to create an intuitive interface definition for Liquid assets.

To illustrate a potential approach, consider the following code snippet. Please note that this is not the final syntax, but merely an example to help visualize the concept:

{% comment %}
  This snippet is designed to render product buy-buttons.
  It accepts several parameters:
  - product: {Object} Represents the product object.
  - block: {Object} Contains information about the block.
  - product_form_id: {String} Identifies the product form.
  - section_id: {String} Specifies the section to which this snippet belongs.
  - show_pickup_availability: {Boolean} Controls whether pickup availability is rendered. If set to true, pickup availability is displayed; if false, it's not (this is optional).

  Here's an example of how you might use it:
  {% render 'buy-buttons', block: block, product: product, product_form_id: product_form_id, section_id: section.id, show_pickup_availability: true %}
{% endcomment %}

karreiro avatar Sep 27 '23 17:09 karreiro