0

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??

  • <?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('static-block-1')->toHtml();?> work for me may be help someone – matinict Apr 26 '18 at 8:39
1

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="Magento\Cms\Block\Block" name="mycustomstaticblock">
        <arguments>
            <argument name="block_id" xsi:type="string">static_block_id</argument>
        </arguments>
    </block>
</referenceContainer>

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="Magento\Cms\Block\Block" 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.

  • thanks , i want to display the static block on all cms pages with 2-columns-layout, Plz can details file name with path. 1. create a new file in your theme: name with extention & full Path. 2. add your static-block to the sidebar file name & path – matinict Mar 21 '18 at 8:50
  • you have to create the cms_page_view.xml file in your custom theme as mentioned above. There you have to insert the code which I wrote. Replace "static_block_id" with the identifier which you chose for your static block – juhanix Mar 21 '18 at 15:38
  • Magento_Cms not found in my theme, can i create this directory or copy from base thme (use porto theme)? – matinict Mar 27 '18 at 5:58
  • work for me Magento_Theme/ – matinict Mar 27 '18 at 6:11

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.