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

anonymous
3,7624 gold badges26 silver badges67 bronze badges
asked Mar 20, 2018 at 10:58
1
  • <?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('static-block-1')->toHtml();?> work for me may be help someone Commented Apr 26, 2018 at 8:39

1 Answer 1

3

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.


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="Magento\Cms\Block\Block" 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 Mar 20, 2018 at 11:21
5
  • 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 Commented Mar 21, 2018 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 Commented Mar 21, 2018 at 15:38
  • Magento_Cms not found in my theme, can i create this directory or copy from base thme (use porto theme)? Commented Mar 27, 2018 at 5:58
  • work for me Magento_Theme/ Commented Mar 27, 2018 at 6:11
  • Please notice that Magento 2.3.4 removed the option to add custom layout updates via admin. Here's the new documentation: devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/… Commented Jul 17, 2020 at 16:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.