I'm trying to add custom block above the footer. I'm adding my custom block in page.xml:

<block type="core/template" template="page/html/socmed_footer.phtml" name="socmed_footer" as="socmed_footer" />

Then i create socmed_footer.phtml in /page/html/socmed_footer.phtml

<div class="socmed_footer">
   <div class="facebook">Facebook</div>
   <div class="line">Line</div>
   <div class="instagram">Instagram</div>

Then i called the custom block in footer.phtml

<div class="footer-container">
<?php echo $this->getChildHtml('socmed_footer') ?>
<div class="footer">
    <?php echo $this->getChildHtml() ?>
    <address class="copyright"><?php echo $this->getCopyright() ?></address>

It's working, but why my footer showing duplicate socmed_footer.phtml inside footer-container and also footer class?

Thank you


Why duplicate socmed_footer.phtml inside footer-container and also footer class

As at footer.phtml,you have call getChildHtml() so it is automatically call all child blocks of footer block.

For this issue you need to remove $this->getChildHtml('socmed_footer') or

Remove socmed_footer block from layout code and call this socmed_footer Progratcally at footer.phtml using below code

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('page/html/socmed_footer.phtml')->toHtml();?> 

The reason is that call getChildHtml()draws all blocks. You need to specify a certain block that should be drawn in case you want to avoid this problem.

  • This is correct, but i have to define each childhtml, thanks btw! – firewalls May 26 '16 at 11:24

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.