Magento 2 – Issue Adding Custom Top Links in Header

magento2toplinks

I am trying to add custom top link via custom module.

File /app/code/<VendorName>/Inquiry/view/frontend/layout/default.xml

If I used <referenceBlock name="header.links"> then its working fine.

<body>
    <referenceBlock name="header.links">
        <block class="Magento\Framework\View\Element\Html\Link" name="inquiry.link" before="-">
            <arguments>
                <argument name="label" xsi:type="string" translate="false">Inquiry</argument>
                <argument name="path" xsi:type="string" translate="false">inquiry</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>

But, If I used <referenceBlock name="top.links"> then it is not working.

<body>
    <referenceBlock name="top.links">
        <block class="Magento\Framework\View\Element\Html\Link" name="inquiry.link" before="-">
            <arguments>
                <argument name="label" xsi:type="string" translate="false">Inquiry</argument>
                <argument name="path" xsi:type="string" translate="false">inquiry</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>

Can anyone guide me here, what is going wrong with second code? Because in Google search result everywhere peoples has suggested <referenceBlock name="top.links"> but it is not working in my custom module. As well same code is written in magento 2 core module. I stuck here..

Best Answer

Finally, I found the solution.

I am using luma theme in magento 2. In luma theme new block has been created under header.panel container. Luma has Extend the base layout to add a block.

File: vendor/magento/theme-frontend-luma/Magento_Theme/layout/default.xml

while in magento blank theme it has created with the name of top.links

File: vendor/magento/theme-frontend-blank/Magento_Theme/layout/default.xml

I got this solution from http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-practice.html

Related Topic