How to creat and call static block in magento 2


How to create magento static block and how to call CMS page, phtml file and XML file.

Please follow example code.
________________________________________________________________________________

How To create Static Block

Step 1 : Content > Blocks


Step 2 : Click to Add New Block

Step 3 : Enter your Block name ID name and save block



How to call statick block in magento 2

Magento 2 static block call in phtml file.

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


Magento 2 static block call in CMS page

 {{block class="Magento\\Cms\\Block\\Block" block_id="example-name"}}  


Magento 2 static block call in XML file

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




No comments:

Post a Comment

Know us

Contact us

Name

Email *

Message *