Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DOC

Get the Static Block Content in Controller

Today we will learn how we can get the cms/static block content in Controller’s action file.
Here we go.

To get the job done, we need to use the following classes :

\Magento\Cms\Model\Block
\Magento\Cms\Model\Template\FilterProvider

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$block = $objectManager->create(\Magento\Cms\Model\Block::class);
$storeId = 1;//it can be any active store id.
$blockId = 12;// it can be any available block id.
$block->setStoreId($storeId)->load($blockId);
$html = $objectManager->create(\Magento\Cms\Model\Template\FilterProvider::class)->getBlockFilter()->setStoreId($storeId)->filter($block->getContent());

This is a simple code that helps us to get the html content of the static/cms block to use it further.
happy coding :).

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • highriskgateways
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home