Magento 2 Different ways to use static blocks

Cms Static block is most powerful where we want to place static content but we can change it by admin.

Direct place static content and change directly to files it's not recommended now a days. we should have control to change static contents. we can also reuse code in other places it's also a feature.

Add CMS Static Block.

Admin > Content > Blocks

Let's take an example, We have added Footer Links Block with Identifier footer_links.

Now we will discuss different ways of use.

I have found 3 different ways where we can call cms block. i am sharing with you my experiments.

1 - Layout xml file.

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

reference name can be change as per requirement where we want to place static block.

2 - Cms Content

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

3 - Directly in .phtml files.

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

This amazing feature of magento cms static block is so much useful.

That's It...!!! Have A Nice Day...!!!

Experienced Magento Certified Developer with a demonstrated history of working in the information technology and services industry. Skilled in SQL, PHP, XAMPP, jQuery, and Microsoft Office. Strong engineering professional with a Master of Computer Applications


Post a Comment

Popular Posts

Have You Any Questins Let Us Know.

Contact Us
Ahmedabad India