1

I want to add a new landing page between cart and checkout page of Magento. I succeeded in adding a new phtml file with the help of controller function.

public function linkAction() { 
   echo $this->getLayout()->createBlock('core/template')->setTemplate('vatexempt/checkou‌​t/onepage/vatexempt.phtml')->toHtml(); 
}

But I am facing a weird issue, I am not getting header and footer in this template file.

dotancohen
  • 1,115
  • 6
  • 18
Pratik bhatt
  • 1,490
  • 13
  • 37
  • Please add the layout xml file you are using for this page. – Sander Mangel Oct 16 '14 at 09:53
  • 1
    @Sander I am calling it with the controller function on click event. – Pratik bhatt Oct 16 '14 at 09:53
  • How you call it is not the point :) please add the layout XML file where the header and footer are included and perhaps paste the contents of your controller file – Sander Mangel Oct 16 '14 at 09:55
  • 1
    this is the content of my controller filepublic function linkAction() { echo $this->getLayout()->createBlock('core/template')->setTemplate('vatexempt/checkout/onepage/vatexempt.phtml')->toHtml(); } – Pratik bhatt Oct 16 '14 at 09:56

1 Answers1

3

By inserting a block via the controller you are not using the full power of templating in Magento. In you module add a layout xml to accomplish this.

your modules config.xml

<frontend>
    [...]
    <layout>
        <updates>
            <helloworld>
                <file>vatexempt.xml</file>
            </helloworld>
        </updates>
    </layout>
    [...]
</frontend>

and in your controller file

public function linkAction()
{
    $this->loadLayout();
    $this->renderLayout();
}

the layout file design/frontend/[package]/[template]/layout/vatexempt.xml

<?xml version="1.0"?>
<layout>
    <vatexempt_index_link> <!-- frontendname_controllername_actionname -->
        <reference name="content">
            <block type="core/template" name="vatexempt" template="vatexempt/checkou‌​t/onepage/vatexempt.phtml" />
        </reference>
    </vatexempt_index_link>
</layout>
Sander Mangel
  • 37,528
  • 5
  • 80
  • 148