Javascript File For A Specific Theme Style

Hello,

Is it possible to include a custom Javascript file for a specific Theme style. CS-Cart does this for CSS/Less files. But I want to add custom JS code for a specific theme style.

Is this possible?

Thank you!

Assuming you are using the responsive theme (or one built on it), you can simply include js code via the my_changes addon using the hooks/index/scripts.post.tpl file in the my_changes addon template directory (you may have to create the directory). Take a look at this thread for more info: http://forum.cs-cart.com/topic/37758-how-to-add-custom-javascript-with-my-changes-addon/

If you are using a "custom theme" then you may have to contact the theme developer to determine how to implement what you want to do within their theme.

Thank you for your reply.

What I want is a way to call Javascript file for a certain style only (or a certain Layout of my custom theme). What you are describing will make the file applicable to all theme's styles and layouts.

Anyway, I have included my JS code in an HTML with Smarty support block in the required Layout. This way will make the Javascript code be executed only in the Layout where the block is in (this is what I am looking for) Is there any performance/conflict issue with this way?

I mean, Is it ok to have my Javascript code be embedded in a block rather than a separate JS file.

By default, cs-cart defers all JS to the bottom of the page so having it in a block is just fine.

No real downside to having it in the index/scripts.post.tpl will have the code included in the single JS file that is generated for the site. It's then cached in the user's Browser. Obviously you would want the code within a function that would be called in the places needed (or in events) , but having it part of the single JS file has no downside (unless it's huge).

By default, cs-cart defers all JS to the bottom of the page so having it in a block is just fine.

Good to know that. Thank you!

So I will go with the block mode.

Appreciated!

Note that you can check used style with the following code

{if $runtime.layout.style_id == 'aaa'}
    
{/if}

Note that you can check used style with the following code

{if $runtime.layout.style_id == 'aaa'}
    
{/if}

Thank you!

Please check your inbox.