Search code examples
javascriptglobal-variablessmartyprestashop-1.6

Global JS variable in Prestashop 1.6


Where the global JS variable should be declared in Prestashop 1.6, so every .tpl would have access to it?

global.js doesn't make it.

And the code like this, placed in .tpl:

 <script type="text/javascript">
 // <![CDATA[
 var test = "test";
 //]]>
 </script>

works for the exact .tpl only


Solution

  • Try this (in Hook methods like hookDisplayHeader or in your front controllers):

    Media::addJsDef([
                    'Modal' => true,
                    'AjaxNum' => 5
                ]);
    

    In other case, you can put your js files in "themes\YOUR-THEME\js\autoload" directory. This only affects the front office