4

In magento1 we use this reference to add block after body tag.

<reference name="after_body_start">
</reference>

same also use in magento 1

 <reference name="before_body_end"></reference>

what is replacement of this code in magento 2?

12

You can check inside page_layout/empty.xml file inside module-theme/base folder.

<container name="after.body.start" as="after.body.start" before="-" label="Page Top"/>

<container name="before.body.end" as="before_body_end" after="-" label="Page Bottom"/>

You can check reference from vendor/magento/module-catalog/view/frontend/layout/default.xml here also:

<referenceContainer name="after.body.start">
    <block class="Magento\Framework\View\Element\Js\Components" name="head.components" as="components" template="Magento_Catalog::js/components.phtml"/>
</referenceContainer>

So in Magento 2 , you can use referenceContainer node to define same as in Magento 1. Thanks.

1

Refer working example, you can place it default.xml or specific layout file in your module.

<referenceContainer name="content">
<block class="Vendorname\Modulename\Block\Manufacturer\Grid" name="manufacturer_grid" template="templates\test.phtml"  before="before.body.end">
            </block>
</referenceContainer>   

If you want to add before or after you can create reference container as posted.

before= "before.body.end"
after = "before.body.end"

Here is an excellent answer from Raphael

Hope this helps ....:)

  • @Qaisar Satti , I added this in my module ( Vendorname\Modulename\view\frontend\layout\default.xml ), it is working fine. you can not find the string name="before_body_end" anymore in Magento 2. check the file \vendor\magento\module-theme\view\adminhtml\page_layout\admin-1column.xml it is name="before.body.end" as="before_body_end" the name is used as an alias. we have to use reference container name as i mentioned to add phtml. – Krishna ijjada May 27 '16 at 9:53

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.