scripts hook help v4

In design/themes/basic/templates/addons we have a file called scripts.post.tpl with the following:

{script src=“addons/my_changes/myscript.js”}



What is the correct folder/path location for myscript.js file that we want to include as a script hook?



We tried creating a folder design/themes/basic/js/addons/my_changes/myscript.js and several other folder paths with no success. We know our script works because we have added it to the main scripts.tpl. But we want to do this properly so we aren't modifying core code.



BTW, we have auto cache refresh turned on. Also, the mystyle.css is working fine using the styles.post.tpl.

Your hook file (the one that declares your myscript.js file) goes in:

design/themes/basic/templates/addons/my_changes/hooks/index/scripts.post.tpl



The content of that file seems to be correct. The myscript.js file needs to go into

design/thems/basic/templates/addons/my_changes/myscript.js (but I would suggest you create a js directory here and adjust the paths).

Then I must be having a syntax problem.



If I add the script directly into basic/templates/common/scripts.tpl it works perfectly.

I place it at the bottom of the script below the hook call and before the end tag as follows:



{hook name=“index:scripts”}

{/hook}



{/scripts}



But when I place it in the file basic/templates/addons/mychanges/myscript.js it fails to work.

I have tried it with the script tags, without the script tags and by adding literal tags around it. What am I missing?



For the record my basic/templates/addons/my_changes/hooks/index/scripts.post.tpl is

{script src=“addons/my_changes/myscript.js”}

[quote]



But when I place it in the file basic/templates/addons/mychanges/myscript.js it fails to work

[/quote]

Assuming this is a typo… mychanges needs to be my_changes



did you clear both the registry and template cache with “?cc&ctpl”?



The way it works is the template engine looks for design/themes/basic/addons/my_changes/hooks/index/scripts.post.tpl

It loads the instructions from that file which in your case tells it to find a js file in

design/themes/basic/addons/my_changes/myscript.js

It should then go ensure that file is referenced in the combined javascript that is created.



Note that js/css files are cleared via the 'cc' parameter and not via the 'ctpl' parameter (goofy I know, but that's how they did it).

I have done same of what @thirnseth said.



Still to make the script work just copy the script and paste it in scripts.post.tpl file it will work as well.

Hopefully your memory is better than mine so a year from now when you do an upgrade that modifies that file you will remember that you modified the core code. Not the way to do it. But a bigger hammer almost always works. Just have to watch your fingers.

Thanks tbirnseth, yes, that was a typo. The correct file and path I am using is:

design/themes/basic/templates/addons/my_changes/hooks/index/scripts.post.tpl



which has the following:



{script src=“addons/my_changes/myscript.js”}



Then:

design/themes/basic/templates/addons/my_changes/myscript.js



has the following:



$(document).ready(function(){

$(‘#product_inquiry’).css(“color”,“#ff0000”);



// $(‘#product_inquiry’).siblings(‘.icon-popup’).addClass(‘product_inquiry’);

});



I have cleared cache and template. Still not showing up in the compiled js. And I don’t have a good memory :)

And you do not find you code in the js that is referenced by the tag in your page header (I.e. the consolidated/compressed file)?

Sorry for the delay. Had to get other pieces of store built. Decided I would try two things. First, a different script. So trying to put Facebook Share button in which requires a script.



So: design/themes/basic/templates/addons/my_changes/hooks/index/scripts.post.tpl is:

{script src=“addons/my_changes/myscript.js”}



and: design/themes/basic/templates/addons/my_changes/myscript.js is




Did not work. To make sure the script is valid I pasted it into scripts.post.tpl and voila, it worked. But this is bad to modify core code.
So I changed scripts.post.tpl to be [b]full path[/b] to script:
{script src="http://domainname.com/cscart/design/themes/basic/templates/addons/my_changes/myscript.js"}

It did not work. Seems the template engine is not using the scripts.post.tpl or it doesn't recognize it properly.

Found a solution for the Facebook script. Facebook says to put it right after the body tag. So I created content.pre.tpl in addons/my_changes/hooks/index and it works. content.pre.tpl is


```php


```

Then, also need the tags in meta header so meta.post.tpl is:

```php {strip}
{if !$smarty.foreach.bkt.first}{$i.title}{if !$smarty.foreach.bkt.last} :: {/if}{/if}
{/foreach}
{if !$skip_page_title}{if $breadcrumbs|count > 1} - {/if}{$location_data.page_title}{/if}
{/if}" />
{/strip}



{assign var="url" value="`$config.current_location`/`$config.current_url`"|fn_url}

```

Apparently in V4, JS is not theme dependent (not sure why, seems kinda dumb) but it isn't.

your scripts need to be in the

js/addons/my_changes

directory which starts in the root of your store I believe that is where the {script} tag is telling the system to look for your file.