php - showing module code once when multiple joomla modules in same page -
in joomla menu item page placed same module instances multiple times(i duplicated in module manager).now it's severe requirement codes of module have 1 time in page.because module's each instance injects same code again , again. how avoid codes appear in page once when have multiple module instances of module in same page? searching through web found unreliable ways -
1.using session in module track whether same module loading 2 or more times , restrict code injecting 1 time 2.using constant way - if(!defined('module_already_loaded')){ //echo codes want done once //this set constant , other modules won't load/echo code define('module_already_loaded', true); }
but not sure how compatible 2nd way joomla 2.5 joomla 3 versions !.if there better error free way provide me asap.
in module code, can use addscript method (it checks duplicate scripts) instead of writing js directly. so, externalize scripts, in code :
$document = jfactory::getdocument(); $document->addscript('your_script.js');
Comments
Post a Comment