Magento 2 – Adding CSS Class or Div Wrapper to a Block

layoutmagento2xml

I have the below XML which adds my static block to the page sidebar, then removes the wishlist. I would like to add a div wrapper to this static block with a css class.

I thought this could be done with the following argument, but it does not work.

<argument name="css_class" xsi:type="string">faq</argument>

Here is the full XML so far if anyone could help it would be appreciated.

<referenceContainer name="sidebar.additional">
   <block class="Magento\Cms\Block\Block" name="faq_sidebar">
       <arguments>
            <argument name="block_id" xsi:type="string">faq_sidebar</argument>
            <argument name="css_class" xsi:type="string">faq</argument>
       </arguments>
   </block>
</referenceContainer>

Best Answer

You can add class like this

<referenceContainer name="sidebar.additional" htmlClass="css_class" htmlTag="div">
   <block class="Magento\Cms\Block\Block" name="faq_sidebar">
       <arguments>
            <argument name="block_id" xsi:type="string">faq_sidebar</argument>
            <argument name="css_class" xsi:type="string">faq</argument>
       </arguments>
   </block>

Check this http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-types.html

Related Topic