Skip to content

Instantly share code, notes, and snippets.

@AndreaRivadossi
Last active January 7, 2021 14:08
Show Gist options
  • Save AndreaRivadossi/21ad5e467f469837fefacdeced4d674f to your computer and use it in GitHub Desktop.
Save AndreaRivadossi/21ad5e467f469837fefacdeced4d674f to your computer and use it in GitHub Desktop.
Magento 2 - Add a CMS static block in a .phtml or .xml layout file
<?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('my-custom-block')->toHtml(); ?>
{{block class="Magento\Cms\Block\Block" block_id="my-custom-block"}}
<block class="Magento\Cms\Block\Block" name="my-custom-block">
<arguments>
<argument name="block_id" xsi:type="string">my-custom-block</argument>
</arguments>
</block>
<?php echo $this->getChildHtml('my-custom-block'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment