Magento 2 – Adding a Class to Block

headermagento2xml

I have the following custom xml inside of my Magento_theme > layout > default.xml

<referenceBlock name="top.links">

            <block class="Magento\Framework\View\Element\Html\Link" name="contactus.link"  after="my-account-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">Contact Us</argument>
                    <argument name="path" xsi:type="string" translate="false">contact-us</argument>
                </arguments>
            </block>

            <block class="Magento\Framework\View\Element\Html\Link" name="aboutus.link" after="contactus.link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">About Us</argument>
                    <argument name="path" xsi:type="string" translate="false">about-us</argument>
                </arguments>
            </block>

            <referenceBlock name="register-link" remove="true" />
            <referenceBlock name="authorization-link" remove="true" />
            <referenceBlock name="wish-list-link" remove="true" />
            <reeferenceBlock name="my-account-link" remove="false" />

        </referenceBlock>

Im removing blocks and adding custom ones in.

What I'd like to to is add a class to the two custom blocks – aboutus.link and contactus.link – how do i go about doing this? Or can it not be done with xml.

Best Answer

You can add css as described below by the element

name="class"

    <block class="Magento\Framework\View\Element\Html\Links" name="header.links">
        <arguments>
            <argument name="label" xsi:type="string" translate="false">Text</argument>
           <argument name="path" xsi:type="string" translate="false">Text</argument>
            <argument name="class" xsi:type="string">header links</argument>
        </arguments>
    </block>