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();
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).
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.
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!
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With