0

I want to create a custom top link in magento 2 for my custom module, but when i load the home page, the custom top link doesn't show up, here's my view/frontend/layout/default.xml:

<?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="header.links">
         <block class="Lime\Confirmation\Block\Link" name="add-new-header-link">
             <arguments>
               <argument name="label" xsi:type="string" translate="true">Confirm Payment</argument>
               <argument name="path" xsi:type="string" translate="true">confirmation</argument>
             </arguments>
         </block>
     </referenceBlock>
</body>

My Block/Link.php:

namespace Lime\Confirmation\Block;

class Link extends \Magento\Framework\View\Element\Html\Link
{
/**
* Render block HTML.
*
* @return string
*/
protected function _toHtml()
    {
     if (false != $this->getTemplate()) {
     return parent::_toHtml();
     }
     return '<li><a ' . $this->getLinkAttributes() . ' >' . $this->escapeHtml($this->getLabel()) . '</a></li>';
    }
}
  • Have you flushed your magento cache after updating the xml? – Rendy Eko Prastiyo Feb 6 '17 at 9:04
0
<reference name="top.links">
  <action method="addLink" translate="label title" module="your module">
    <label>Confirm Payment</label>
    <url helper="chechout/success"/>
    <title>Confirm Payment</title>
    <position>10</position>
   </action>
</reference>
0

The top link block name is top.links not header.links:

<?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="top.links">
            <block class="Lime\Confirmation\Block\Link" name="add-new-header-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="true">Confirm Payment</argument>
                    <argument name="path" xsi:type="string" translate="true">confirmation</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

Note : Make sure your clear the cache after replacing the code

  • still not working – simple guy Feb 6 '17 at 9:22
  • Have you flushed your magento cache after updating the xml? – Rendy Eko Prastiyo Feb 6 '17 at 9:25
  • Why do you use custom block Lime\Confirmation\Block\Link while you can use magento 2 default block class of Magento\Framework\View\Element\Html\Link? – Rendy Eko Prastiyo Feb 6 '17 at 9:27
  • i already do setup:upgrade, because i want to add it from my custom module – simple guy Feb 6 '17 at 9:41
  • Have you tried using Magento\Framework\View\Element\Html\Link as your block class? – Rendy Eko Prastiyo Feb 6 '17 at 9:46

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.