4

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.

1 Answer 1

7

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();
3
  • 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
    Commented Jun 4, 2016 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 Commented Jun 4, 2016 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. Commented Jun 4, 2016 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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