Hey, Magento buddies
In today’s learning tutorial, we will learn about How to Show Cms Static Block From Template phtml File in Magento 2.
CMS Static Blocks are an excellent way to display various information to your consumer. CMS Static Blocks help to get more consumer’s attention to specific products and also make your Magento 2 store or website more attractive. You can show CMS Static Blocks practically on each and every page of your Magento 2 website and Magento 2 store.
If you don’t want to consume too much time in configuring CMS Static Block, then you can call CMS Static Block in phtml or by using XML file layout. Let’s go step by step.
Steps to Show Cms Static Block From Template phtml File in Magento 2
Step 1: Add the below code in your phtml file when you show Static block
1 2 3 4 5 6 7 |
<?php echo $this->getLayout() ->createBlock(\Magento\Cms\Block\Block::class) ->setBlockId('block_identifier_here') ->toHtml(); //change block_identifier_here with Your CMS Block Identifier ?> |
Step 2: Add below code CMS static block in your CMS page.
1 |
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier_here"}} |
Final words
So, in this tutorial article, we learn How to Show Cms Static Block From Template phtml File in Magento 2. If any confusion occurs, feel free to reach us via the comments. Share it with your Magento buddies.
Happy learning!