I have a custom.js.liquid
file under my assets folder, and I have added this line to theme.liquid
.
<script src="{{ 'custom.js' | asset_url }}" defer="defer"></script>
I am trying to output a product's title to javascript, in custom.js.liquid
, I put
console.log({{ all_products['absolut-vodka'] | json }});
This line can't be recognized by the .js.liquid file. In frontend, in the custom.js
file it becomes
console.log(null);
On the other hand, if I put
<script>console.log({{ all_products['absolut-vodka'] | json}});</script>
in the theme.liquid
file, it can output the correct object.
What did I do wrong?