When I explored the header links and footer links inside the files of Magento 2, the links are declared like each in one seperate default.xml file inside individual modules. But the links are displayed in same block at frontend as list elements. The phtml coding is different from Magento 1.9.x. My doubt is how they are grouping the seperately declared blocks (in default.xml) and displaying in frontend as a single block elements (list) using phtml files.

Can someone please explain the concept in easily understandable way. Am a beginner in php coding and newbie to Magento 2.

Explanation with a sample phtml file example:footer.phtml is most welcomed.

1 Answer 1


First of all, footer.phtml file doesn't seem to be used anywhere, just in single Test class.

But speaking about concept, this is pretty easy :) You can create single block, with single .phtml template file. And by using referenceBlock in other modules you are still working with the same block.

In this situation we have block with Magento\Framework\View\Element\Html\Links class and footer_links name. In other modules we can add more links to this block by using <referenceBlock name="footer_links"> and those links will be visible in previously created block. Simple as it. Hope you understood my explaination :)

  • what does the line <?php echo $block->getChildHtml() ?> in footer.phtml mean. can you explain that too?
    – Ramya
    Apr 25, 2016 at 7:23
  • 2
    When you add child blocks to (in this example) footer block, this is the way to output those in your template. This function gets all of them and return in place where you use this function. You can also pass name as parameter of this function. If you declare two blocks as children, lets say 'child-block-1' and 'child-block-2' by using <?php echo $block->getChildHtml('child-block-1') ?> you can echo only single of them. Apr 25, 2016 at 7:25
  • 1
    I'm not sure what you mean by grouping. In your layout files you can nest blocks. This function returns all blocks that are nested inside your current block, one level below. Apr 25, 2016 at 7:28
  • 1
    I'm not sure, but this file also doesn't seem to be used anywhere. Links in footer are created by _toHtml function of Magento\Framework\View\Element\Html\Link class Apr 25, 2016 at 7:35
  • 1
    No, it's defined in module-theme\view\frontend\page_layout\1column.xml by <container name="footer-container"> This is the name you can reference to by referenceContainer Apr 25, 2016 at 7:43

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.