static block in phtml magento 2 code example

Example 1: magento2 add static block in phtml

<?= $block->getChildHtml('my-main-phtml-block-cms') ?>

Example 2: magento2 add static block in phtml

<referenceBlock name="my-main-phtml-block">    <block class="Magento\Cms\Block\Block" name="my-main-phtml-block-cms">        <arguments>            <argument name="block_id" xsi:type="string">my_cmsblock_identifier</argument>        </arguments>    </block></referenceBlock>

Example 3: magento 2 add in static block

<?php    echo $this->getLayout()        ->createBlock(\Magento\Cms\Block\Block::class)        ->setBlockId('my_cmsblock_identifier') //replace my_cmsblock_identifier with real CMS bock identifier        ->toHtml();?>

Tags:

Misc Example