---
title: "How to Get CMS Block Collection in Magento 2?"
url: "https://magecomp.com/blog/get-cms-block-collection-magento-2/"
date: "2023-09-18T13:23:05+00:00"
modified: "2025-02-12T12:31:23+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 287
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Retrieve the collection of CMS blocks in your Magento 2 store and enhance functionality. Check out the steps through this guide"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Create Credit Memo Programmatically Using Root Script in Magento 2?"
    url: "https://magecomp.com/blog/create-credit-memo-programmatically-using-root-script-magento-2/"
  - title: "How to Hire Magento Developer for Your Magento 2 Stores?"
    url: "https://magecomp.com/blog/hire-magento-developer-guide/"
  - title: "How to Make Purchase Order Number Field Optional in Magento 2?"
    url: "https://magecomp.com/blog/make-purchase-order-number-field-optional-magento-2/"
---

# How to Get CMS Block Collection in Magento 2?

_Published: September 18, 2023_  
_Author: Dhiren Vasoya_  

![How to Get CMS Block Collection in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/09/How-to-Get-CMS-Block-Collection-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

In today’s blog, we will learn How to Get CMS Block Collection in Magento 2.
One of the key features of Magento 2 is the Content Management System (CMS), which enables you to create and manage static content such as pages and blocks. In this blog post, we will focus on how to retrieve a collection of CMS blocks in Magento 2 programmatically.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-4.webp)](https://magecomp.com/services/hire-magento-programmer/)

Before starting with obtaining CMS blocks collection, check out the below links
- [**How to Create New CMS Block in Magento 2**](https://magecomp.com/blog/create-new-cms-block-in-magento-2/)
- [**How to Add Dynamic CMS Block Programmatically in Magento 2**](https://magecomp.com/blog/add-dynamic-cms-block-programmatically-magento-2/)

Let’s jump into the steps to get CMS block collection in Magento 2.
## Steps to Get CMS Block Collection in Magento 2:
**Step 1:** Create a **CmsBlockcollection.php** file inside the Block folder.
**app\code\Vendor\Extension\Block**

Now add the code as follows.
```
<?php
namespace VendorExtensionBlock;

use MagentoCmsApiBlockRepositoryInterface;
use MagentoFrameworkApiSearchCriteriaBuilder;

class CmsBlockcollection extends MagentoFrameworkViewElementTemplate
{
   protected $blockRepository;
   protected $searchCriteriaBuilder;

   public function __construct(
         MagentoFrameworkViewElementTemplateContext $context,
         BlockRepositoryInterface $blockRepository,
         SearchCriteriaBuilder $searchCriteriaBuilder,
         array $data = []
         )
   {
       $this->blockRepository = $blockRepository;
       $this->searchCriteriaBuilder = $searchCriteriaBuilder;
       parent::__construct($context, $data);
   }
      public function getCmsBlockcollection() {
        $searchCriteria = $this->searchCriteriaBuilder->create();
        $cmsBlockscollection = $this->blockRepository->getList($searchCriteria)->getItems();
        return $cmsBlockscollection;
    }
}
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Step 2:** Now, get all CMS block collection in phtml file using the below code.
```
<?php
	$cmsBlockscollection = $block->getCmsBlockcollection();
	foreach($cmsBlockscollection as $cmsBlock) {
	    echo $cmsBlock->getTitle();
	    echo $cmsBlock->getId();
           print_r($cmsBlock->getData());
	}
?>
```

## Conclusion:
This way, you can retrieve CMS block collection in Magento 2. If you have any doubt, let me know through the comment box. Share the tutorial with your friends and stay in touch with us.
[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-4.webp)](https://magecomp.com/magento-malware-removal.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/get-cms-block-collection-magento-2/](https://magecomp.com/blog/get-cms-block-collection-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-12 12:40:20 UTC_  
