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

I insert the static cms block through the widget instance - and I would like to output the title of the static block, as well as its contents, from 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 this to getData () to see what could capture that the following:

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

So, I guess the only way is to use block_id to get the header, but I can't figure out how to do this. I can grab the block_id from there using $ this-> getBlockId (), but how can I use this to get the header?

I thought the following might work, but it is not:

 $blockid = $this->getBlockId(); $blocktitle = Mage::getModel('cms/page')->load($blockid, 'block_id')->getTitle(); 
+7
source share
3 answers

It seems that the following works:

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

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

+9
source

If you have several stores and you want the vault to be enabled, it looks like this:

 $title = Mage::getModel('cms/block') ->setStoreId(Mage::app()->getStore()->getId()) ->load($blockId) ->getTitle(); 
+1
source

An alternative approach is to create a function for it on your block:

 public function getContactWidgetHtml() { $result = ''; $widget = Mage::getModel('widget/widget_instance')->load(14); if ($widget && $widget->getId()) { $widgetBlock = $this->getLayout() ->createBlock( $widget->getType(), $widget->getTitle(), $widget->getWidgetParameters() ); if ($widgetBlock) { $result = $widgetBlock->toHtml(); } } return $result; } 

And then display it in your template using:

 echo $this->getContactWidgetHtml(); 
0
source

All Articles