0

I've been following this tutorial on Inchoo Magento – Custom email contact form with notification system

I've have it working, but he has the code to display the contact form on a three comlumn layout and I need to have it display on the one column layout. Here is the code I believe is relavent:

<?php
class Inchoo_SimpleContact_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        //Get current layout state
        $this->loadLayout();
        $block = $this->getLayout()->createBlock(
            'Mage_Core_Block_Template',
            'inchoo.simple_contact',
            array(
                'template' => 'inchoo/simple_contact.phtml'
            )
        );

        $this->getLayout()->getBlock('content')->append($block);
        //$this->getLayout()->getBlock('right')->insert($block, 'catalog.compare.sidebar', true);
        $this->_initLayoutMessages('core/session');
        $this->renderLayout();
    }

    public function sendemailAction()
    {
        //Fetch submited params
        $params = $this->getRequest()->getParams();
        $mail = new Zend_Mail();
        $mail->setBodyText($params['comment']);
        $mail->setFrom($params['email'], $params['name']);
        $mail->addTo('mail@mybelovedangels.com', 'Some Recipient');
        $mail->setSubject('Test Inchoo_SimpleContact Module for Magento');
        try {
            $mail->send();
        }
        catch(Exception $ex) {
            Mage::getSingleton('core/session')->addError('Unable to send email. Sample of a custom notification error from Inchoo_SimpleContact.');


        }
        //Redirect back to index action of (this) inchoo-simplecontact controller
        $this->_redirect('inchoo-simplecontact/');
    }
}
?> 

I've been searching on the net for the answer but I haven't had in luck getting anything to work. I think it has something to do with Mage_Core_Block_Template.

4

1 回答 1

1

Grab your layout handle (something like inchoo_simplecontact_index_index) and do some layout.xml magic:

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

Maybe the handle is naemd differently, grab it in the called controller via:

Zend_Debug::dump(Mage::app()->getLayout()->getUpdate()->getHandles());

or do it via code:

$template = Mage::getConfig()->getNode(‘global/page/layouts/one_column/template’);
$this->getLayout()->getBlock(‘root’)->setTemplate($template);

Good luck!

于 2013-06-20T11:18:03.757 回答