Introduction
I’m sure you know how to do it.
Just paste the following code into the necessary *.phtml template and that’s it:
<?php
echo $this->getLayout()
->createBlock(\Magento\Cms\Block\Block::class)
->setIdentifier('block_identifier')
->toHtml();
?>
But!
Did you know that the \Magento\Cms\Block\Block is depricated since magento 2.4.2 ?
So, the solution above is work for Magento 2.4.1 and less.
And for Magento 2.4.2 and higher the solution below.
Solution
If you updated to the newest Magento version (2.4.2 and higher) you just need to find and replace the
\Magento\Cms\Block\Block::class
with the
\Magento\Cms\Block\BlockByIdentifier::class
So, the code should be
<?php
echo $this->getLayout()
->createBlock(\Magento\Cms\Block\BlockByIdentifier::class)
->setIdentifier('block_identifier')
->toHtml();
?>
That’s it 🙃
And please, don’t forget to replace the
block_identifierwith your’s CMS-Block identifier.
Happy codding !