Magento - Getting the title of a cms static block from it's block_id?

Magento - Getting the title of a cms static block from it's block_id?

October 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - Getting the title of a cms static block from it's block_id?

Retrieving a CMS Static Block Title from its block_id in Magento

Hello developers! Today, I’m going to address a common challenge faced by many while working with Magento’s CMS static blocks - how to retrieve the title of a static block using only its block_id. Let’s dive right into it!

Understanding the Context

The problem states that the developer is inserting a CMS static block via a widget instance and wants to output both the static block title and its content within their widget template. The default Magento template for displaying static blocks simply echoes the text content.

By inspecting the data being passed to the template, we find that it includes information like block_id, module_name, and the actual text content of the block. However, there’s no direct key for the title.

Retrieving the block_id

The first step is to retrieve the block_id. This can be done directly in your widget template using the following line:

$blockid = $this->getBlockId();

This will give you the ID of the static block being displayed.

The Initial Attempt and Why It Fails

The developer then tries to load the CMS page model using the block_id as the identifier and attempts to retrieve the title. However, this fails because in Magento’s database schema, the primary key for a CMS block is not actually named block_id, but rather page_id.

Here’s the incorrect attempt:

$blockid = $this->getBlockId();
$blocktitle = Mage::getModel('cms/page')->load($blockid, 'block_id')->getTitle();

This fails because Magento expects us to use the page_id as the identifier when loading a CMS page model.

The Correct Approach

To correctly retrieve the title of a static block using its ID, we need to use the appropriate primary key. Here’s how you can do it:

$blockid = $this->getBlockId();
$blocktitle = Mage::getModel('cms/page')->load($blockid, 'page_id')->getTitle();

In this code:

  • We first retrieve the block_id using $this->getBlockId().
  • Then, we load the CMS page model with the retrieved ID and use 'page_id' as the identifier.
  • Finally, we call getTitle() to retrieve the title of the static block.

This approach works because it uses the correct primary key (page_id) in the database schema for loading a CMS page model.

Conclusion

Retrieving a CMS static block’s title using its block_id is indeed possible, but requires understanding Magento’s data structure. By correctly using the page_id as the identifier when loading the CMS page model, you can successfully retrieve and display the title of your static blocks alongside their content in your widget templates.

Remember, always refer to Magento’s official documentation for more detailed information on working with CMS blocks and other Magento features. Happy coding!

Don’t forget to leave any questions or additional insights you might have about this topic in the comments below!

Database Extensions Themes Errors

Our network