1

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..

  • I think it depend header.links but not top.links – Bill Dec 9 '15 at 12:02
  • @PaW, but in core module magento used top.links. file: \vendor\magento\module-customer\view\frontend\layout\default.xml – Praful Rajput Dec 9 '15 at 12:03
  • because it using <move element="register-link" destination="header.links"/> in Luma Theme so it move to header.links – Bill Dec 9 '15 at 12:21
  • Yes, I also got this one. I mentioned it into below answer. Thanks PaW. – Praful Rajput Dec 9 '15 at 12:37
5

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

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.