Locksmith isn't protecting product or variant data in a Liquid snippet

In cases where a theme sets up a custom variable name for a product object, like this:

<!-- templates/product.liquid -->
{% assign thing_that_has_a_price = product %}

... and then includes a snippet that depends on that variable name, like this:

<!-- snippets/price.liquid -->
{{ thing_that_has_a_price.price }}

... you'll find that Locksmith won't automatically update that data in order to reflect protected variants. This is because Locksmith doesn't have enough information, within the context of that snippet's code, to determine that the custom variable should be treated as a product.

To work around this, Locksmith supports some limited type hinting. As in other languages, we bring a Locksmith-specific implementation to Liquid, allowing you to "hint" that a specific variable should be treated as a product, and protected as such.

The usage is simple: add the following line to the file containing the custom variable, substituting some_variable with the name of your variable.

{% assign __locksmith_declare_product = some_variable %}

Adjusting our snippet example from earlier, we might use this:

<!-- snippets/price.liquid -->
{%- assign __locksmith_declare_product = thing_that_has_a_price -%}
{{ thing_that_has_a_price.price }}

The result: Locksmith will register the variable as containing a product object, and will correctly update it to respect locked variants.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.