Import/export JavaScript function between liquid

Hi,

I am having an issue about JavaScript function that uses liquid variables.

I have a liquid file called “x.liquid” and its’ content:

// x.liquid

I want to use this function “sayHello” in other file called “y.liquid” like this:

//y.liquid

{% include 'x' %}

Is it possible to import/export JavaScript function (that use liquid variables inside) from one liquid file to another?

If so, what is the correct way to do so? because this way doesn’t work.

Thanks,
Tom

Hi @TomCalmigo ,

This is impossible with .liquid files. You can just add the code directly at the layout/theme.liquid file.
Ex: https://i.imgur.com/GwYSesO.png
Then you can get it out in any liquid files, just like your y.liquid declaration.
And you don’t need this code:
{% include ‘x’ %}

Hope it is clear to you.

If my answer can help you solve your issue, please mark it as a solution. Thank you and good luck.

This is not possible with .liquid files.

You can just add the code directly at the layout/theme.liquid file.

Ex: https://i.imgur.com/GwYSesO.png

Then you can get it out in any liquid file, just like your y.liquid declaration.

And you don’t need this code: {% include ‘x’ %}

Hope it clear to you.

Hi @LitCommerce , we can’t use liquid but can use the normal import and export to js files? Thanks