1

I can not understand where this path is

"Magento\Framework\View\Element\Html\Links"

I want to understand how this piece of code works

<referenceContainer name="header.panel">
        <block class="Magento\Framework\View\Element\Html\Links" name="header.links">
            <arguments>
                <argument name="css_class" xsi:type="string">header links</argument>
            </arguments>
        </block>
    </referenceContainer>

1 Answer 1

2

You can see this file under Magento_root/vendor/magento/framework/View/Element/Html/Links.php And below code :

<referenceContainer name="header.panel">
   <block class="Magento\Framework\View\Element\Html\Links"name="header.links">
   <arguments>
     <argument name="css_class" xsi:type="string">header links</argument>      
   </arguments>
</block>
</referenceContainer>

This above code works to add your custom links in the top header section. If you can see at the bottom of Links.php file there is a function which works to bind the links:

protected function _toHtml()
{
    if (false != $this->getTemplate()) {
        return parent::_toHtml();
    }

    $html = '';
    if ($this->getLinks()) {
        $html = '<ul' . ($this->hasCssClass() ? ' class="' . $this->escapeHtml(
            $this->getCssClass()
        ) . '"' : '') . '>';
        foreach ($this->getLinks() as $link) {
            $html .= $this->renderLink($link);
        }
        $html .= '</ul>';
    }

    return $html;
}

Hope this helps you !!!

1
  • If this answer helps you. Kindly give me +ve vote. Aug 3, 2018 at 0:04

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.