Magento – Call PHTML from another PHTML

magento-1.9phtml

I have a link in the top header, once user clicks on it, it will open a modal. I want the modal to contain the contents of customer account page where he can edit his password, etc. How do I call it using a method like

echo $this->getLayout()->createBlock('core/template')->setTemplate('test/test.phtml')->toHtml();

?>

In short, customer account pages contain the list of items (My Wish list, Acount Information, Address Book, etc). I want to show in this modal only the content of Account Information which he will be able to update password, email, Avatar etc.

Best Answer

I don't recommend this method, better define your modal in your layout.xml and then include it via:

<div class="modal">
    <?php echo $this->getChildHtml('modal'); ?>
</div>

Layout.xml should look something like this:

<default>
    <reference name="top.menu">
        <block type="customer/form_edit" name="modal" template="customer/form/edit.phtml"/>
    </reference>
</default>

If you want it your way, it should look like this:

echo $this->getLayout()->createBlock('customer/form_edit')
    ->setTemplate('customer/form/edit.phtml')->toHtml();
Related Topic