jumbo Posted October 26, 2011 Share Posted October 26, 2011 Hi guys I would like to understand how PS loads the JS files in header.tpl In the code: {if isset($js_files)} {foreach from=$js_files item=js_uri} <script type="text/javascript" src="{$js_uri}"></script> {/foreach} {/if} What does $js_files stand for? How does PS select the $js_files? There's a bunch of .js files in the root js dir and the theme's js dir, however not all of them are selected 1 Link to comment Share on other sites More sharing options...
jumbo Posted October 27, 2011 Author Share Posted October 27, 2011 I'm surprised no one answered this yet... Link to comment Share on other sites More sharing options...
jumbo Posted October 31, 2011 Author Share Posted October 31, 2011 up up up Link to comment Share on other sites More sharing options...
jumbo Posted November 15, 2011 Author Share Posted November 15, 2011 hello? Link to comment Share on other sites More sharing options...
goodok Posted January 13, 2012 Share Posted January 13, 2012 I need also this information. is there any way to add new js file in this loop? Link to comment Share on other sites More sharing options...
kristjan07 Posted March 28, 2013 Share Posted March 28, 2013 +1 for this question Link to comment Share on other sites More sharing options...
yaniv14 Posted March 28, 2013 Share Posted March 28, 2013 (edited) I know very little about php but... {foreach} is how a loop called in Smarty (php template render engine). So basically its doing a loop to retrieve all available JS files, I think its looking for all available files ending with JS in 'root/js' and in 'themes/current_theme/js' those location defines in 'defines_uri.inc.php' Its loading neccassary JS based on modules transplant in header Edited March 28, 2013 by yaniv14 (see edit history) Link to comment Share on other sites More sharing options...
Whispar1 Posted March 28, 2013 Share Posted March 28, 2013 If I am not mistaken, like Yaniv - PHP is not my strong suit, its the controller.php for whatever page is being loaded that determines what files are loaded. For instance cms pages use CmsController.php to call css/scripts necessary to render that page in public function setMedia() public function setMedia() { parent::setMedia(); if ($this->assignCase == 1) $this->addJS(_THEME_JS_DIR_.'cms.js'); $this->addJS(_THEME_JS_DIR_.'jquery-1.3.2.js'); $this->addCSS(_THEME_CSS_DIR_.'cms.css'); } If you are looking to add your own css/js this is where you would add it. Maybe someone can add to this to confirm or point you in the right direction Link to comment Share on other sites More sharing options...
Nuno Loureiro Posted July 27, 2013 Share Posted July 27, 2013 (edited) Hi there! $js_files is defined as global array ( public $js_files = array(); inside of controller.php ) That means every js file inside that array will be loaded on header of webpage (with foreach function). Like Whispar1 said, controllers call css/scripts ( addJS or addCSS function) necessary to render that page in public function setMedia(). If you want to see what is inside of that array and loaded on any page add {$js_files|@print_r} to tpl. Edited July 27, 2013 by Nuno Loureiro (see edit history) Link to comment Share on other sites More sharing options...
SmartDataSoft Posted July 28, 2013 Share Posted July 28, 2013 (edited) {if isset($js_files)} {foreach from=$js_files item=js_uri} <script type="text/javascript" src="{$js_uri}"></script> {/foreach} {/if this load the theme js file which is inside the themes->mythemes->js folder. and also those js file which is also inside themes->mythemes->js->modules folder on theme directory and also load the controller addJs method assigned js file. This is a global smarty variable. Hope you understand. Edited July 28, 2013 by smartdatasoft (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts