Get CMS Block Collection in Magento 2.

You can get all the CMS Static Blocks collection in Magento 2 by calling interface, Magento\Cms\Api\BlockRepositoryInterface.

Magento\Cms\Api\BlockRepositoryInterface used for getting CMS Static Blocks related data in Magento 2.

BlockRepositoryInterface is used when you need to fetch a collection of CMS Static blocks or get specific CMS static block data. You can get Specific Blocks data by Identifier using  Get Cms Blocks data by an identifier.

You need to instantiate Magento\Cms\Api\BlockRepositoryInterface in __construct() method of Class.

From Template file, You can access all the Static Block by iterate over a loop on a collection.

Based on the above Code snippet you get all the Cms Static Blocks from a store. You can also get specific Static Blocks based on your custom condition by refer link.

Leave a Reply

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