Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

magento

I'm inserting a cms static block via a widget instance - and I'd like to output the static block title as well as it's content, from within my widget template. The default template (app/design/frontend/base/default/template/cms/widget/static_block/default.phtml) simply has:

<?php echo $this->getText(); ?>

I changed that to getData() instead to see what it was possible to grab, which is the following:

[type] => cms/widget_block
[block_id] => 11
[module_name] => Mage_Cms
[text] => blahblahblah

So I'm guessing the only way is to use the block_id to get the title, but can't quite figure out how. I can grab the block_id from there with $this->getBlockId() - but then how do I use that to get the title?

I thought the following might work but it doesn't:

$blockid = $this->getBlockId();
$blocktitle = Mage::getModel('cms/page')->load($blockid, 'block_id')->getTitle();
like image 880
Marlon Creative Avatar asked Nov 15 '12 11:11

Marlon Creative


People also ask

How do you call a CMS block in XML?

Except for displaying CMS block on CMS Page or CMS Block, showing it on category page there is an option to call CMS block programmatically using XML file. You need to replace "my_cmsblock_identifier" with your CMS block Identifier or ID (we recommend to use Identifier).

How do I display CMS block in Magento 2?

Use the below code snippet if you want to show CMS Static Block from template phtml file in Magento 2: echo $this->getLayout() ->createBlock('Magento\Cms\Block\Block') ->setBlockId('your_block_identifier') ->toHtml(); For another block within CMS Block in Magento 2, please use the below code to show it.


2 Answers

Seems the following works:

$blockid = $this->getBlockId();
$block = Mage::getModel('cms/block')->load($blockid);
echo $block->getTitle();

Always helps to write out a question here, half the time seeing it written helps me find the answer myself!

like image 149
Marlon Creative Avatar answered Sep 23 '22 15:09

Marlon Creative


If you have several stores and you want for the store you are on, it is like that:

$title = Mage::getModel('cms/block')
    ->setStoreId(Mage::app()->getStore()->getId())
    ->load($blockId)
    ->getTitle();
like image 29
Kervin Ramen Avatar answered Sep 23 '22 15:09

Kervin Ramen