SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH

How to Call Static Block in Phtml File in Magento 2

Today, I will guide you on how to call static block in file phtml. With static block, you can easy to edit, add new content for it.

First Step: Create new static block

Admin Panel > CONTENT > Elements > Blocks > Add New Block > 
add information bellow for static block bellow and click Save button.

Enable Block: slect Enable (You can enable or disable block).
Block Title: Name of the block to easily identify the purpose of creating the block.
Identifier: Enter a unique block identifier(We usually use it to call static block).
Store View: Select the store views to show the static block in.
Block Content: Add content of the block.

Second Step: Call static block in phtml file

In before step, I have created a static block with identifier is magepow_block_identifier. I will call this static block to phtml file. Here is some ways to call it.

Call your static block in phtml file:

<?php
echo $this->getLayout()
->createBlock(‘Magento\Cms\Block\Block’)
->setBlockId(‘magepow_block_identifier’)
->toHtml();
?>

Display Static Block In CMS Page or Static Block:

{ {block class=”Magento\\Cms\\Block\\Block” block_id=”magepow_block_identifier”} }

Display CMS Static Block In XML:

Code to show the CMS Static Block in the “Content”

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

Or you can use xml and phtml to show static block:

<referenceBlock name=“magepow-phtml-block”>
    <block class=“Magento\Cms\Block\Block” name=“magepow-phtml-block-cms”>
        <arguments>
            <argument name=“block_id” xsi:type=“string”>magepow_block_identifier</argument>
        </arguments>
    </block>
</referenceBlock>

Add this code to you file xml

display it in PHTML file with getChildHtml block method

<?= $block->getChildHtml(‘magepow-phtml-block-cms’) ?>

Now, you can easy to edit that static block in the backend.