2

Can you please let me know how to add JS/CSS via a controller method

I tried this but isn't working

$head = $this->getLayout()->getBlock('head');
$head->setCanLoadExtJs(true);
$head->addItem('skin_adminhtml', 'adminhtml/testimonial.css');

1 Answer 1

3

Try this,

$this->getLayout()->getBlock('head')->addJs('jsfile.js'); //To add root js folder
$this->getLayout()->getBlock('head')->addItem('skin_js','jsfile.js'); //To add js file under the /skin folder
$this->getLayout()->getBlock('head')->addItem('skin_css','cssfile.css'); //To add css file under the /skin folder

Hope it will help you!

2
  • Hi Rani, My code is working fine as I did some mistake in config.xml block. $head = $this->getLayout()->getBlock('head'); $head->setCanLoadExtJs(true); $head->addItem('skin_css', 'testimonial.css'); But, I appreciate your help ... !!
    – user55967
    Commented Jul 15, 2017 at 5:04
  • Great 😀 thank you Commented Jul 16, 2017 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.