3

I want to add static block in page (.phtml) template.

I followed these steps:-

Step1: Navigate to CONTENT >Blocks >Add New Block.

Step 2: Create a Static Block (My_block).

Now I want to add this Block in page template.

I want to do something like below: $this->getLayout()->createBlock('cms/block')->setBlockId('your_block_id')->toHtml();

please let me know how to add this static block in my page (.phtml) template.

mahipal negi
  • 317
  • 2
  • 15

2 Answers2

3

Display Static Block in Phtml file & CMS page

In XML File:

<referenceContainer name="content">
    <block class="Magento\Cms\Block\Block" name="block_identifier">
        <arguments>
            <argument name="block_id" xsi:type="string">block_identifier</argument>
        </arguments>
    </block>
</referenceContainer>

In Phtml File:

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>

In CMS Content:

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
Amaresh Tiwari
  • 947
  • 13
  • 36
Amuk Saxena
  • 1,521
  • 4
  • 18
  • 44
0

To add CMS block in to page:

Call into HTML Show/Hide Editor

use this Code

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}

Another Method is to call through Widgets:

In the Editor click on the insert Widget and fill out respective inputs.