Magento 2 add static block in Layout XML

Here is a quick way on how to add static cms block in the layout

Display CMS Static Block In Phtml File:

Here the code to show CMS Static Block in any template (phtml) file in Magento 2,



->createBlock('Magento\Cms\Block\Block')
->setBlockId('block_identifier')
->toHtml();
?>

Display CMS Static Block In CMS Content:

Here the code to show CMS Static Block in any other CMS static block/page in Magento 2,


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

Display CMS Static Block In XML:
Here the code to show CMS Static Block in any layout (XML) file in Magento 2,

 

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

 

 

Thanks to info at http://www.blogtreat.com/magento-2-how-to-call-cms-static-block-in-phtml-file/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s