Or from any code location with the block id:-
class MyBlock
{
/**
* @var \Magento\Cms\Model\Template\FilterProvider
*/
protected $_filterProvider;
/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
* Block factory
*
* @var \Magento\Cms\Model\Block
*/
protected $_block;
/**
* @param Magento\Framework\View\Element\Template\Context $context
* @param Magento\Store\Model\StoreManagerInterface $storeManager,
* @param Magento\Cms\Model\Template\FilterProvider $filterProvider,
* @param Magento\Cms\Model\BlockFactory $blockFactory,
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Cms\Model\Template\FilterProvider $filterProvider,
\Magento\Cms\Model\BlockFactory $blockFactory,
array $data = []
) {
$this->_storeManager = $storeManager;
$this->_filterProvider = $filterProvider;
$this->_block = $blockFactory->create()->setStoreId(
$storeManager->getStore()->getId()
);
parent::__construct($context, $data);
}
/**
* @return string
*/
protected function getHtml() {
$html = '';
if($this->getCustomBlockId()){
$this->_block->load($this->getCustomBlockId());
if($this->_block->isActive())
$html = $this->_filterProvider->getBlockFilter()->setStoreId(
$this->_storeManager->getStore()->getId()
)->filter($this->_block->getContent());
}
return $html;
}
}