Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Javascript File For A Specific Theme Style. Rate Topic   - - - - -

 
  • alaa
  • Advanced Member
  • Trial users
  • Join Date: 18-Mar 18
  • 69 posts

Posted 04 May 2018 - 10:22 PM #1

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! 



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10839 posts

Posted 04 May 2018 - 11:08 PM #2

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...-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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • alaa
  • Advanced Member
  • Trial users
  • Join Date: 18-Mar 18
  • 69 posts

Posted 04 May 2018 - 11:15 PM #3

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. 



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10839 posts

Posted 04 May 2018 - 11:21 PM #4

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).


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • alaa
  • Advanced Member
  • Trial users
  • Join Date: 18-Mar 18
  • 69 posts

Posted 04 May 2018 - 11:26 PM #5

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! 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18006 posts

Posted 07 May 2018 - 05:39 AM #6

Note that you can check used style with the following code

{if $runtime.layout.style_id == 'aaa'}
    <script type='text/javascript' src='....'></script>
{/if}

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • alaa
  • Advanced Member
  • Trial users
  • Join Date: 18-Mar 18
  • 69 posts

Posted 08 May 2018 - 10:19 AM #7

 

Note that you can check used style with the following code

{if $runtime.layout.style_id == 'aaa'}
    <script type='text/javascript' src='....'></script>
{/if}

 

Thank you! 

 

Please check your inbox.