mike10101 Posted August 23, 2017 Share Posted August 23, 2017 Hello, I am working on a module and I'm trying to add a small jquery plugin I need for the product page. Using the old method $this->context->controller->addJs() the jquery plugins gets added BEFORE bundle.js where jquery is... well... bundled.. and the plugin can't bind to jquery before its loaded. Is there some kind of method I'm not aware to add js files after bundle.js in the new symfony admin pages ? Otherwise I am forced to inject the file with js which is not cool. Side note: why can't we post issues on the github repo ?? Its such a shame I can't post this on github. - mike Link to comment Share on other sites More sharing options...
mike10101 Posted August 24, 2017 Author Share Posted August 24, 2017 bump Link to comment Share on other sites More sharing options...
Geo Burlibasa Posted September 12, 2017 Share Posted September 12, 2017 #upI have the same problem. Link to comment Share on other sites More sharing options...
BonPresta Posted September 12, 2017 Share Posted September 12, 2017 Hello, I am working on a module and I'm trying to add a small jquery plugin I need for the product page. Using the old method $this->context->controller->addJs() the jquery plugins gets added BEFORE bundle.js where jquery is... well... bundled.. and the plugin can't bind to jquery before its loaded. Is there some kind of method I'm not aware to add js files after bundle.js in the new symfony admin pages ? Otherwise I am forced to inject the file with js which is not cool. Side note: why can't we post issues on the github repo ?? Its such a shame I can't post this on github. - mike Hello, If you try so: public function install() { parent::install(); $this->registerHook('actionAdminControllerSetMedia'); return true; } public function hookActionAdminControllerSetMedia($params){ $this->registerStylesheet('module-namemodule-css','modules/namemodule/views/css/namemodule.css'); $this->registerJavascript('module-namemodule-js','modules/namemodule/views/js/namemodule.js'); } Link to comment Share on other sites More sharing options...
Geo Burlibasa Posted September 18, 2017 Share Posted September 18, 2017 Hello, If you try so: public function install() { parent::install(); $this->registerHook('actionAdminControllerSetMedia'); return true; } public function hookActionAdminControllerSetMedia($params){ $this->registerStylesheet('module-namemodule-css','modules/namemodule/views/css/namemodule.css'); $this->registerJavascript('module-namemodule-js','modules/namemodule/views/js/namemodule.js'); } Unfortunately in AdminController there is not registerJavascript. Only in FrontController. Link to comment Share on other sites More sharing options...
GKentaurus Posted September 18, 2017 Share Posted September 18, 2017 (edited) Hi everyone: To BackOffice try this: public function hookBackOfficeHeader(){ if (Tools::getValue('configure') == $this->name || Tools::getValue('module_name') == $this->name) { $this->context->controller->addJS($this->_path.'views/js/back.js'); $this->context->controller->addCSS($this->_path.'views/css/back.css'); [spam-filter] To FrontOffice try this: public function hookDisplayHeader(){ if ('order' === $this->context->controller->php_self) { $this->context->controller->registerStylesheet('modules-front', 'modules/'.$this->name.'/views/css/front.css', array('media' => 'all', 'priority' => 150)); $this->context->controller->registerJavascript('modules-front', 'modules/'.$this->name.'/views/js/front.js', array('position' => 'bottom', 'priority' => 150)); [spam-filter] Hope this be usefull and can help you Edit:Obviously, install the hooks you need Edited September 18, 2017 by GKentaurus (see edit history) Link to comment Share on other sites More sharing options...
Geo Burlibasa Posted September 18, 2017 Share Posted September 18, 2017 Hello GKentaurus, The problem is not that we cannot add any JS in backoffice. The problem is that we cannot add jquery plugins (actually we can add, but won't work). And this is because jQuery is loaded AFTER we add other js files. Of course, we can add it before too with $this->context->controller->addJquery(), but this won't solve the problem because jQuery will be re-initialised (because of the original way the library is loaded) and all the plugins added before that won't work. Link to comment Share on other sites More sharing options...
Edvinas Posted March 23, 2018 Share Posted March 23, 2018 On 18/09/2017 at 4:59 PM, Geo Burlibasa said: Hello GKentaurus, The problem is not that we cannot add any JS in backoffice. The problem is that we cannot add jquery plugins (actually we can add, but won't work). And this is because jQuery is loaded AFTER we add other js files. Of course, we can add it before too with $this->context->controller->addJquery(), but this won't solve the problem because jQuery will be re-initialised (because of the original way the library is loaded) and all the plugins added before that won't work. Did you find a solution??? Link to comment Share on other sites More sharing options...
phinq1910 Posted March 24, 2018 Share Posted March 24, 2018 You can try add on template file. Also, for jquery conflict, try replace jquery by xjQuery and remove $ variable in jquery.js Hope help you Link to comment Share on other sites More sharing options...
jc37 Posted September 5, 2019 Share Posted September 5, 2019 hello guys, In your module class, you must register this hook "actionAdminControllerSetMedia" then use it public function install() { parent::install(); $this->registerHook('actionAdminControllerSetMedia'); return true; } public function hookActionAdminControllerSetMedia(){ $this->context->controller->addJquery(); $this->context->controller->addJS(_MODULE_DIR_.'moduleName/views/js/jsFileName.js'); } And On 9/18/2017 at 2:38 PM, Geo Burlibasa said: Unfortunately in AdminController there is not registerJavascript. Only in FrontController. Like you said we're in adminController so we must use "addJS" function 1 Link to comment Share on other sites More sharing options...
diondlemarcu Posted March 31, 2020 Share Posted March 31, 2020 (edited) On 8/23/2017 at 3:28 PM, mike10101 said: Hello, I am working on a module and I'm trying to add a small jquery plugin I need for the product page. Using the old method $this->context->controller->addJs() the jquery plugins Showbox jiofi.local.html tplinklogin gets added BEFORE bundle.js where jquery is... well... bundled.. and the plugin can't bind to jquery before its loaded. Is there some kind of method I'm not aware to add js files after bundle.js in the new symfony admin pages ? Otherwise I am forced to inject the file with js which is not cool. Side note: why can't we post issues on the github repo ?? Its such a shame I can't post this on github. - mike bump Edited March 31, 2020 by diondlemarcu (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now