TransWikia.com

How insert static block all CMS page sidebar left sidebar Magento 2.x?

Magento Asked by matinict on November 23, 2021

I want insert static block all cmd page sidebar left sidebar magento 2.x

Step1:
I create a static block that i want to add to a specific CMS page which name static-block-1 .

ex.

<div class=”element-blue”>
        <h3>Static Block 1</h3>
        <p>This is display on left sidebar on cms page</p>
</div>

Setp2:

How Can I display on CMS Page Left Sidebar??

One Answer

If you want to display the static block on all cms pages with 2-columns-layout:

create a new file in your theme:

<magento-root>/app/design/frontend/<Vendor>/<theme>/Magento_Cms/layout/cms_page_view.xml

and add your static-block to the sidebar.

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="sidebar.additional">
            <block class="MagentoCmsBlockBlock" name="mycustomstaticblock">
                <arguments>
                    <argument name="block_id" xsi:type="string">static_block_id</argument>
                </arguments>
            </block>
        </referenceContainer>
    </body>
</page>

Keep in mind that the CMS-page needs to be set to 2-columns.


EDIT: REMOVED IN VERSION 2.3.4 but still possible in prior versions - If you want to display your static block on a specific cms page:

Navigate to to your CMS-Page:

Content -> Pages -> Your CMS-Page

go to "Design"

add following code to "Layout Update XML"

<referenceContainer name="sidebar.additional">
     <block class="MagentoCmsBlockBlock" name="mycustomstaticblock">
        <arguments>
            <argument name="block_id" xsi:type="string">static_block_id</argument>
        </arguments>
    </block>
</referenceContainer>

Take a look at the new documentation at https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/xml-manage.html#create-cms-pageproductcategory-specific-layouts for Magento versions 2.3.4 or above as mentioned by @Luis Paulo Lohmann

Answered by juhanix on November 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP