Magento - How do you return results of unlimited CMS Static blocks (with certain "Identifier") to a CMS Page

Magento - How do you return results of unlimited CMS Static blocks (with certain "Identifier") to a CMS Page

August 31, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - How do you return results of unlimited CMS Static blocks (with certain "Identifier") to a CMS Page

Magento Tutorial: Return Results of Unlimited CMS Static Blocks with Certain Identifier

Hey there fellow Magento developers! I know how challenging it can be to work with static blocks and CMS pages sometimes. In this tutorial, we’ll explore how you can return results from a specific set of static blocks with the same identifier prefix to your CMS page.

Understanding Your Current Setup

Firstly, let’s break down what you’ve shared:

  1. You have a group of static blocks starting with an identifier prefix “testimonial-” (e.g., testimonial-1, testimonial-2).
  2. You’re trying to pull these into a .phtml file located in app/design/frontend/[package]/[template]/template/page/.
  3. You’re using the block type=“core/template” template=“page/name.phtml” identifier=“testimonial-” syntax.

It looks like you’ve got most of it figured out, but you’re encountering a problem where only the last static block is being displayed on your CMS page.

The Key to Retrieving All Static Blocks

The issue lies in how you’re setting and retrieving the block ID in your .phtml file. Let’s dive into this:

$_block = $this->getLayout()->createBlock('cms/block')->setBlockId($block_ID);

if ($_block) :

In this section, you’re creating a new block instance for each iteration of your foreach loop and setting the block ID to $block_ID. However, in the subsequent line ($_block = $this->getLayout()->createBlock('cms/block')->setBlockId($block_ID);), you’re overwriting the previously created blocks with a new one.

To fix this, you should initialize your $_block variable outside the loop and only set the block ID inside the loop:

$_block = $this->getLayout()->createBlock('cms/block');
$blockNum = 1;
foreach($collection as $key => $value){
    $_blockId = $this->getIdentifier();
    $block_ID = $_blockId . $blockNum;
    echo "Key: " . $key . " - " . "Block ID: " . $block_ID . "<br />";
    $blockNum++;

    // Set the block ID inside the loop
    $_block->setBlockId($block_ID);
}

In this updated version, we create a single instance of the ‘cms/block’ block and set its ID for each iteration of the loop. This ensures that all your static blocks are displayed correctly on the page.

Conclusion: Displaying All Static Blocks

And there you have it! By initializing your $_block variable outside the loop and setting the block ID inside, you’ll successfully display all the desired static blocks with identifiers prefixed by “testimonial-” on your CMS page.

If you found this tutorial helpful or want to learn more advanced Magento development techniques, feel free to check out my other articles at LaravelCompany. I’m always excited to share my knowledge and help fellow developers grow!

Happy coding!

Themes Configuration Pricing Errors

Our network