bondimedical Posted May 5, 2016 Share Posted May 5, 2016 I am looking at starting to sell my first CubeCart extension. How do I get CubeCart to load the CSS from my extension. I noticed there is a script on the bottom of CubeCart which loads all Javascript. How do I add my .js file to this? Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 5, 2016 Share Posted May 5, 2016 With a hook. In the GUI __construct() function, there are hooks for: 1) class.gui.head_js 2) class.gui.body_js 3) class.gui.javascripts These statements will be in an appropriately named hook file(s) in the plugin's /hooks/ folder: 1. $head_js[] = either <script src="wherever"></script> tags or actual <script>javascript</script>. 2. $body_js[] = either <script src="wherever"></script> tags or actual <script>javascript</script>. 3. $js[] = must be the relative path to the file containing the javascript, such as: $js[] = "modules/plugins/my_plugin/js/script1.js"; The Foundation template has: Near the top: {foreach from=$HEAD_JS item=js}{$js}{/foreach} Near the bottom: {foreach from=$BODY_JS item=js}{$js}{/foreach} {foreach from=$JS_SCRIPTS key=k item=script} <script src="{$STORE_URL}/{$script|replace:'\\':'/'}" type="text/javascript"></script> {/foreach} Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 6, 2016 Share Posted May 6, 2016 Just to add a bit more info. The hooks for: 1) class.gui.head_js 2) class.gui.body_js 3) class.gui.javascripts are processed when Cubecart first starts up. Therefore, if you are wanting to construct the javascript with dynamic data, you will need to assemble it in the hook file. For example: $body_js[] = 'var foo = "' . $some_developed_aspect_about_the_product_being_viewed . '";'; That won't work because nothing about the product has been assembled at this point. I had to use the class.gui.display hook (last hook executed), fetch the array BODY_JS template variable back from Smarty, add the plugin's javascript to that array, then assign it back to BODY_JS. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.