1

I had these blocks in the frontend layout:

<referenceContainer name="content">
    <block class="Dfl\Marketplace\Block\Profile" name="marketplace_sellerprofile" template="profile.phtml" cacheable="false" before="-"/>
</referenceContainer>
<referenceContainer name="sidebar.main">
    <block class="Dfl\Marketplace\Block\Profile" name="marketplace_sellerprofileleft" template="profile_left_sidebar.phtml" cacheable="false" before="-"/>
</referenceContainer>
<referenceContainer name="sidebar.additional">
    <block class="Dfl\Marketplace\Block\Profile" name="marketplace_sellerprofileright" template="profile_right_sidebar.phtml" cacheable="false" before="-"/>
</referenceContainer>

then i wanted to add a new block in order to insert it in the section. I added the following command above these blocks

<referenceBlock name="head.additional">
  <block class="Dfl\Marketplace\Block\Profile" name="marketplace_social_tags" template="social_tags.phtml" />
</referenceBlock>

then in my social_tags.phtml template I just added a simple meta entry.

enter image description here

Then I run setup:upgrade and setup:static-content:deploy en_US es_ES But the entry wasn't there in the head tag. I followed these links yet i was unable to display the meta entries.

Adding blocks to the head section in Magento 2

magento-2-adding-arbitrary-html-to-the-head-of-every-page

Any help? What it's missing?

2

Create default.xml in app/code/Dfl/Marketplace/view/frontend/layout

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
    <referenceBlock name="head.additional">
        <block class="Magento\Catalog\Block\Product\View" name="marketplace_social_tags" template="Dfl_Marketplace::social_tags.phtml"/>
    </referenceBlock>
</body>

Create social_tags.phtml in app/code/Dfl/Marketplace/view/frontend/templates

<meta proerty="og:imagen" content="TEST_CONTENT" />

Run Magento frontend and check view-source

enter image description here

  • Hello, We have added below code to our extension default.xml file but its not working. – Vish Mar 29 '18 at 9:56
  • <referenceContainer name="head.additional"> <block class="Magento\Catalog\Block\Product\View" name="rtest" template="Test_Module::test.phtml"/> </referenceContainer> – Vish Mar 29 '18 at 9:56
  • 2
    @Vish it is not referenceContainer it is referenceBlock – Sumit Kumar May 22 '18 at 14:18
1

There was an issue related with the path. Was View by default i changed to view and the template worked and the meta content appeared.

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.