What I need to do is, if a person search for a product then if products found the layout need to be page/2columns-left.phtml with layered navigation but if there were no results then its layout should be page/1column.phtml and it will display new products, popular products.

One of the solution I came around is to override the CatalogSearch/ResultController's indexAction() where I can get whether $query->getNumResults() is 0 or not. On that basis how could I load layout differently?

If there's another better approach to this, that would be helpful too.


1.Add layout handle in catalogsearch.xml:

    <reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
    <reference name="content">
        <!--  add your blocks here-->

2.Load this handle in controller:

public function indexAction()
     * some codes here

    if ($someValueIsTrue) {

| improve this answer | |
  • perfect! exactly the same thing what I wanted. I was missing $this->loadLayoutUpdates();. Can you tell me what is the order of calling these functions? Is there any blog or tutorial on it? – Mohammad Faisal Feb 7 '14 at 5:00
  • @MohammadFaisal see public function loadLayout() of Mage_Core_Controller_Varien_Action class. Our logick is same as logic of this function. – mageUz Feb 7 '14 at 6:15
  • I'd previously tried $this->loadLayout('NO_SEARCH_RESULTS'); but it doesn't worked that time? – Mohammad Faisal Feb 7 '14 at 6:20
  • 1
    In this case default handle will not added to layout updates. See public function loadLayout() for understanding the logic. – mageUz Feb 7 '14 at 6:23
  • 1
    You could also do $this->loadLayout(array('default','NO_SEARCH_RESULTS'). – benmarks Mar 31 '14 at 12:33

Take a look at this article: http://sandersluis.com/2011/11/changing-the-page-template-in-a-magento-controller/. Hope this helps.

| improve this answer | |
  • not the answer I'm looking for. it just tell about changing the template. and i'm looking for rendering the layout xml – Mohammad Faisal Feb 7 '14 at 5:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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