4

When I create a new page in Magento 2 using the "two columns with left bar" layout it by default puts the wishlist in there.

Using the "layout update XML" in the design options tab I can remove that using this:

<referenceBlock name="wishlist_sidebar" remove="true"/>

What I also want to do is replace it with my own static block. I thought something like the following would do the trick but it does not. Can someone help?

<container name="sidebar.additional">
   <block class="Magento\Cms\Block\Block" name="test" />
</container>
10

To reference a container you need to use referenceContainer as opposite to referenceBlock to reference a block.

The container tag is used to create a container as the block tag is used to create a block.

In your case, the right code would be:

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

This is assuming your cms block id is test, you'll need to replace that value in case it is different

  • Is it's necessary to put block class="Magento\Cms\Block\Block" name="test"> ?? – Arunendra Apr 13 '16 at 13:33
  • @Arunendra yes it is required – Raphael at Digital Pianism Apr 13 '16 at 13:33
  • Thank you all for the solution! Does anyone know if it is possible to add a css class / div wrapper to the block using XML? Or is the best way to just wrap the contents of the block in a div manually? – caffeinehigh Apr 13 '16 at 14:14
  • @user1837290 please ask a different question for that, it'll have a better visibility and you'll get help easily – Raphael at Digital Pianism Apr 13 '16 at 14:17
  • @RaphaelatDigitalPianism thank you, will do :) – caffeinehigh Apr 13 '16 at 14:18
2

It should work like this

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

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.