Skip to content

Instantly share code, notes, and snippets.

@devudit
Last active November 22, 2017 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devudit/c1eb0b7a22c8c33ae4da262e2ef4d797 to your computer and use it in GitHub Desktop.
Save devudit/c1eb0b7a22c8c33ae4da262e2ef4d797 to your computer and use it in GitHub Desktop.
Call static block in page
<?php
// If you want to call static block in page
// Try below code :
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
?>
<?php
//If you want to call in phtml file :
//Try below code :
echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();
?>
<?php
Your xml file code should be :
<referenceContainer name="sidebar.additional">
<block class="Magento\Cms\Block\Block" name="yourblockid">
<arguments>
<argument name="block_id" xsi:type="string">yourblockid</argument>
</arguments>
</block>
</referenceContainer>
//At Last if you want to call phtml with your block in cms page :
//Try below code :
{{block class="Magento\Modulename\Block\Blockname" template="Magento_Modulename::templatefilename.phtml"}}
// Refrence:- https://chetansanghani.wordpress.com/2015/11/20/magento2-display-static-block-in-phtml-file-cms-page/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment