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 someonematinict– matinict2018年04月26日 08:39:19 +00:00Commented Apr 26, 2018 at 8:39
1 Answer 1
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
-
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 & pathmatinict– matinict2018年03月21日 08:50:06 +00:00Commented 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 blockjuhanix– juhanix2018年03月21日 15:38:49 +00:00Commented 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)?matinict– matinict2018年03月27日 05:58:21 +00:00Commented Mar 27, 2018 at 5:58
-
work for me Magento_Theme/matinict– matinict2018年03月27日 06:11:44 +00:00Commented 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/…Luis Paulo Lohmann– Luis Paulo Lohmann2020年07月17日 16:35:54 +00:00Commented Jul 17, 2020 at 16:35