0

How can I replace the HTML Class of the top links block? I thought I can do it by overriding this class https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/View/Element/Html/Links.php

But not sure if it is the right thing to do, please advise.

1 Answer 1

1

You can add class using argument

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

To add the class to link, for example I've added custom-class to registration link as below in default.xml

<referenceBlock name="top.links">
    <block class="Magento\Customer\Block\Account\RegisterLink" name="register-link">
        <arguments>
            <argument name="label" xsi:type="string" translate="true">Create an Account</argument>
            <argument name="class" xsi:type="string" translate="true">custom-class</argument>
        </arguments>
    </block>
</referenceBlock>
3
  • That is the main one, what I am trying to change is the inner links i.e login, it has links class, I want to change that for example.
    – Ibrahim S
    Mar 20, 2021 at 17:25
  • The links class you saw is in the template, so you need to overwrite template to get what you want, the Html/Links can't help it
    – Jimmy
    Mar 22, 2021 at 3:49
  • @IbrahimS I've updated my answer, please check it will help you. Mar 22, 2021 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.