1
votes

Thanks in advance,

I want to change the product listing page layout dynamically..

The question is that if in the list.phtml if i click on grid link the layout of the list.phtml file should be 2columns-right.phtml and if i click on list link the layout should be 2columns-left.phtml

i have used following code for this but no luck yet ..

if($this->getMode() == 'grid' && $this->getLayout()->getBlock('root')->getTemplate() != 'page/2columns-left.phtml'):
$this->getLayout()->getBlock('root')->setTemplate('page/2columns-right.phtml');
elseif($this->getMode() == 'list' && $this->getLayout()->getBlock('root')->getTemplate() != 'page/2columns-right.phtml'):
$this->getLayout()->getBlock('root')->setTemplate('page/2columns-left.phtml');
endif;

var_dump($pageLayout=$this->getLayout()->getBlock('root')->getTemplate());

does any one have done this before..

1

1 Answers

0
votes

I think you put this code in a place where the root block is already loaded.

One possibility is to use css, put the listing in 3 columns mode and hide the undesired column + change the width of the main column using css depending on "$this->getMode()".

Another way is to create controllers to generate the whole body page for list and for grid and use AJAX to populate the page when changing the mode.