Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Changing content block dynamically
 
MrConfused
Jr. Member
 
Total Posts:  3
Joined:  2009-02-03
 

How do I choose/specify the template file to use from within a controller?

I want to have a page that shows default content, this is defined in my layout xml, but I want to be able to change the content to a diffierent template if needed.. but using the same controller function..

ie.

if ($tpl != 'default'{
    
// continue showing the standard template
else {
   
// show template replace.phtml
}

Can you do this easily with magento? Ideally I would like to specify the blocks for all occasions in my layout xml and choose which to load without having to create a totally separate controller function..

 
Magento Community Magento Community
Magento Community
Magento Community
 
miked2004
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2007-12-13
Atlanta, Georgia
 

I am also trying to figure out how to do exactly the same thing.

I assume It would be something like $this->getLayout()-> .....

I just can’t figure out exactly how to do it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
miked2004
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2007-12-13
Atlanta, Georgia
 

Hey I figured out how to add blocks from a controller.

$this->getLayout()->getBlock('content')->append($this->getLayout()->createBlock('customer/form_register''dealer_form_register', array('template'=>'customer/form/registerDealer.phtml')));

I was not able to remove blocks, so I just removed the origional block("layout information") from the layout xml file and am setting it from the controller. Let me know if you figure out how to remode content from the controller.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top