Reading list Switch to dark mode

    Get the Static Block Content in Controller

    Updated 24 July 2019

    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 :


    $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.
    $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 :).

    Start your headless eCommerce
    Find out More
    . . .

    Leave a Comment

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


  • highriskgateways
  • Back to Top

    Message Sent!

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

    Back to Home