Trigger layout handle in another layout handle

In most cases you don’t want to write the same layout declaration twice. With the following snippet you can trigger a once written layout handle in other layout handles. So you can reuse the declaration. <modul_controller_action> <update handle=”modul_controller_action”/><!–layout handle to trigger–> </modul_controller_action>

Add Content In Magento Controller

If you want to add content to the rendered page inside a controller action, you can do it like that: $this->loadLayout(); $message = $this->getLayout() ->createBlock(‘core/text’, ‘ready-block’) ->setText(‘<h1>Testaction for Controller:</h1>’); $this->getLayout()->getBlock(‘content’)->insert($message); $this->renderLayout();  

Add JavaScript or CSS in Block class

 To add JavaScript or CSS files to the head section of the resulting HTML page, you can add something like this to the _prepareLayout function of a Block class: $headBlock = $this->getLayout()->getBlock(‘head’); $headBlock->addJs(‘somefolder/ask-sheldon.js’); $headBlock->addCss(‘somefolder/ask-sheldon.css’); As you can see, we can use the layout model to get the head block an use its functions to add files. This […]