I'm creating a custom controller that uses the same header and footer as the rest of the site, but will be using custom code to serve content, but I also need to exclude them based on query parameters (hence why I'm not using a template file in a cms page for this)

My question is how can I call upon these in a controller? Does renderLayout() accept parameters such as renderLayout('header'), etc.?

2 Answers 2


When you call loadlayout() and renderlayout() in the controller of your model, magento will look for the respective xml(layout) file for your module. In layout file, you can add your content by referencing the content, left or right structure blocks. This automatically loads the header and footer for your file.

You do something like this:

<reference name="content> 
  • I think this may be a more bulletproof way of handling this, since in the controller I can then decide if I should call $this->loadLayout() and $this->renderLayout() based on a query parameter, I will be using this to load a PDF either inline with the website in an iframe or triggering a download, in which case I need to exclude the layout.
    – DWils
    Commented Jun 4, 2014 at 17:45

You should try in controller

    if (youpaamerecondtion){
if you want add block       $block=$this->getLayout()->createBlock('Mage_Core_Block_Template','my_block_name_here',
array('template' => 'activecodeline/developer.phtml')

  • I like this idea, but can I also use the if condition to decide if I should load layout and render layout? Basically I will load a pdf in iframe in content block, or if user wants to download the pdf, using the same url with ?download=1&file=path/to/file.pdf, and using htaccess to redirect requests to pdf files. So if pdf is accessed directly, load in a page, with option to download.
    – DWils
    Commented Jun 4, 2014 at 17:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.