I'm creating a CS-Cart v4.10
addon.
I want to execute some Javascript code from inside the scripts.post.tpl
template hook. I figured this hook out from taking a look at other addons, because actually there is no explanation about how to put Javascript in addons in the official docs.
This hook works fine for other addons, but not for mine. There is no output in the console, and actually my code is not included in the page nor the compiled scripts.
I have read about the my_changes
addon but since I'm actually creating an addon, it doesn't seems a good idea to me to use that way.
The Javascript code is a simple:
console.log('Got executed!');
and I'm putting that single line in the file:
~\cscart\design\backend\templates\addons\a_test_cscart_addon\hooks\addons\scripts.post.tpl
I have also seen people talking about script.tpl
and even scripts_head.tpl
or similar, but still don't know how to get my single liner executed without using the my_changes
addon.
Thanks for your time and help.
If you want the js to be executed in the backend, you have to use this path:
~\cscart\design\backend\templates\addons\a_test_cscart_addon\hooks\index\scripts.post.tpl
then, if you want to only execute some code, let's say in the addons.manage
area of the site, you just do this in the file:
{if ($runtime.controller == "addons" && $runtime.mode == "manage")}
console.log('Got executed!');
{/if}
that is the way you control where the code is executed.