Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 2.0: Adding a static block in a page template

Tags:

magento-2.0

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.

like image 567
mahipal negi Avatar asked Nov 27 '25 05:11

mahipal negi


1 Answers

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"}}
like image 122
Amuk Saxena Avatar answered Dec 02 '25 06:12

Amuk Saxena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!