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.


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'); ?>

Layout.xml should look something like this:

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

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

echo $this->getLayout()->createBlock('customer/form_edit')
| improve this answer | |
  • Thanks Fabian. Is there a reason why second way is not recommended? First one looks more like Magento standard way. But just curious what implication second way may have. – Husanoo Jun 4 '16 at 10:04
  • @Toto it is more of a good practice in my opinion. This way developers see straight away which blocks are child of other blocks without having to look in every template to find out "magic code" like the second one – Raphael at Digital Pianism Jun 4 '16 at 10:18
  • Not sure about implications. 1. But it looks ugly and logic should be avoided in templates. 2. Beside this your colleagues are happy if they find code where it is expected (block -> layout.xml). And third it might be important for (full page) caching. – Fabian Blechschmidt Jun 4 '16 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.