How can I include JS code in theme app extensions?

Hi guys,

how can we include JS code in theme app extensions?

Below tag is not working in app block or snippet

{% javascript %} {% endjavascript %}

Thanks in advance :slightly_smiling_face:

Hi @Girish_Rajwani ,

You can insert import file js, such as:


or insert code js:


It’s not working. giving 404 error.

Below is the code & test.js file is in assets folder of theme app extension

Hi @Girish_Rajwani

I am hoping you can follow. You should have a folder created extensions. You can create a js file in assets folder and call that inside the blocks.

You can then call the script code

You must add this inside your liquid file


Yes i did the exact same but it is giving 404 error in console.

I did pushed my code and extension but after that as well

Let me know if i am missing something

Thanks

Please provide the screen shot to better understand what you have done

PFA Below

Hi Girish_Rajwani,

Please write your JS code in a file name app.js, put it in asset folder

Then declare javascript code for your block as below

{% schema %}
{
“stylesheet”: “app.css”,
“javascript”: “app.js”,
}
{% endschema %}

It would solves your problem.

Regards,

HI @vixnguyen

It’s still showing 404 in console. I included file in asset folder, and added code in blocks liquid file as follows:

{% schema %}
{
“javascript”: “test.js”,
“name”: “Star Rating”,
“target”: “section”
}

{% endschema %}

Is there anything missing?

Hi,

Sorry, my bad. It should be assets. Please try again.

Regards,

Yes @vixnguyen it’s assets folder only but still no luck :slightly_smiling_face: PFA.

Hi Girish_Rajwani,

I think you should remove the block, and deploy the new version of extension. Then add the block to your theme again.

I guess it’s a caching issue.

Regards,

Thanks a ton @vixnguyen . It worked.

hey, I am facing a similar issue. Can you please elaborate If i just have to remove the entire block liquid file or just the inclusion of assets script from liquid file ?

How did you do it @Girish_Rajwani . I am facing a similar issue

Hey @abhishek1108 copy extension folder, remove folder and then create extension and copy. It will work