2

Let's say that we have this controller :

<?php
class Hello_World_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        echo 'Hello Stackers !' ;
    }
}

Obviously, when triggering this controller, we will have a black message Hello Stackers !, and the controller page is not having/importing any theme (JS, CSS) files even in the default (rwd) Magento theme .

How can we import theme in controllers pages ?

androniennn
  • 277
  • 3
  • 12

1 Answers1

2

You can use the following between the loadLayout and the renderLayout method calls:

// In case of a JS file under the /js folder
$this->getLayout()->getBlock('head')->addJs('my.js');
// In case of a JS file under the /skin folder
$this->getLayout()->getBlock('head')->addItem('skin_js','my.js');
// In case of a CSS file under the /skin folder
$this->getLayout()->getBlock('head')->addItem('skin_css','my.css');

If you only need the default theme you need to update your code with the following:

$this->loadLayout();
$this->renderLayout();
Raphael at Digital Pianism
  • 70,385
  • 34
  • 188
  • 352