0

I'm new to magento. I don`t have permission to modify the controller file. So I'm creating new module with block to make my requirement works. Now everything works fine.

But, now based on the condition, i need to load the different layout. (one with left sidebar and another without left sidebar). I have to load the layout xml file through block code.

I don't know how to do with block. Can anyone help me?

2
  • have you tried this solution ??? Commented Jan 1, 2014 at 12:12
  • @Asifhhh I have tried but no solution yet. I think your solution will help me to acheive my target. I'll try and let you know. thanks for answer. Commented Jan 1, 2014 at 13:01

5 Answers 5

1

Hello you set your template into your layout xml like below

<reference name="root">   
      <action method="setTemplate"><template>page/1column.phtml</template></action>   
    </reference>
<reference name="root">   
      <action method="setTemplate"><template>page/2columnleft.phtml</template></action>   
    </reference>
Sign up to request clarification or add additional context in comments.

2 Comments

I need to load the template / layout based on the condition.
1

You can try the below solution. First of all you cannot easly add two different layout for a specific page

<checkout_index_cart>
<reference name="root">
 <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
...
<checkout_index_cart>

<checkout_onepage_index>

<reference name="root">
 <action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
...
<checkout_onepage_index>

Comments

1

Change the page layout on the bases of condition, defined in helper function

<reference name="root">
        <action method="setTemplate"><template helper="modulename/getNewLayoutupdate"/></action>
</reference>

Here is the helper function, make there conditions accordingly

  public function getNewLayoutupdate(){

    $page_layout = Mage::getStoreConfig('customize_your_own');

    switch($page_layout)
    {
        case 'empty':
            $page_layout = 'page/empty.phtml';
            break;
        case 'one_column':
            $page_layout = "page/1column.phtml";
            break;
        case 'two_columns_left':
            $page_layout = 'page/2columns-left.phtml';
            break;
        case 'two_columns_right':
            $page_layout = 'page/2columns-right.phtml';
            break;
        case 'three_columns':
            $page_layout = 'page/3columns.phtml';
            break;
        default:
            $page_layout = 'page/2columns-right.phtml';
    }

    return $page_layout;

}

4 Comments

I have done as you said. but my module helper overrides the existing catalog module helper. so i'm getting error like Namespace_Catalog_Helper_Category_Flat not found
well you do not have your own module's helper ? Data.php ?
how did you set this code ? <template helper="modulename/getNewLayoutupdate"/> and where "getNewLayoutupdate" function is defined ?
Thanks i have fixed. It's simple. Let me answer.
1

I have fixed myself.

In block, changed layout instead of removing left sidebar.

protected function _prepareLayout() {


        if($my_condition)
        {        

            $this->getLayout()->getBlock('root')->setTemplate("page/1column.phtml");

        }

        parent::_prepareLayout();        
        return $this;
    }

Comments

0

You will need to update the layout xml.

Check this tutorial: http://magento-quickies.tumblr.com/post/16336482158/adding-additional-layout-xml-updates-via-modules

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.