Snippet with name "product" has a weird behavior

Hi everyone. I came across this weird issue. When I name a snippet “product” I can not access the product global object inside it.

Is “product” name reserved or something?

This is for compatibility with the old way of calling snippets

It was/is possible to invoke snippet like so:

{% include 'snippet-name' with value %}

Inside the snippet, the variable snippet-name is defined and its value is set to value

So, when the snippet name is literally product, then system is defining a product variable and it’s null if you do not use with or other means to pass variable inside the snippet.

Best practice is to avoid naming your snippets the same as global variables.

1 Like

Thanks for the explanation @tim_1 . Everything makes sense now.

1 Like