I have an interesting situation where on a CMS page, I am defining some new blocks in the update_layout_xml section - that need to be referenced from within the CMS content itself using shortcode syntax {{block ...}}
I know it is possible to define new blocks to be instantiated from a CMS textarea - but is it possible to reference an existing block to define the exact position that it needs to be inserted.
Using update_layout_xml only permits positioning using before= or after= - whereas I need more granular control for positioning the element within the content block itself. If this were to be done via a phtml file - it would just be a case of using getChildHtml - but there doesn't seem to be an equivalent for CMS.
I know I can extend Mage_Widget_Model_Template_Filter and add a new function - but is there already a core method for doing this?
4 Answers 4
I extended Mage_Widget_Model_Template_Filter to add this function and it does the trick, but I was wondering if there was a native way to do it.
public function getchildDirective($construction)
{
 $layout = Mage::app()->getLayout();
 $blockParameters = $this->_getIncludeParameters($construction[2]);
 return $layout->getBlock('root')->getChildHtml($blockParameters['id']);
}
 Depending on your action methods, you should be able to add functionality to the _construct method of your block (as defined by your block type)
But if your action methods are simply setting some variable like
<action method="setCategoryId"><category_id>17</category_id></action>
then you can add those params to your smiley syntax like this:
{{block type="cms/block" block_id="your_block_id" category_id="17"}}
 - 
 It would work in principle, but I have a LOT of parameters to include, so it wouldn't be practical.Fran– Fran2013年05月03日 16:45:53 +00:00Commented May 3, 2013 at 16:45
 
I know you can include static blocks in a CMS content using something like this:
{{block type="cms/block" block_id="your_block_id"}}
I don't see why this method wouldn't work for custom blocks. Have you tried it at least?
It doesn't fix it when the shortcode is in a variable from a module.
Example: I have a slider module, and when I enter {{store direct_url="customer-service"}} as the link attribute, it does not get replaced.
- 
 Please do not use answers for commenting on something. I realize that you need to accrue 50 rep before being able to comment on posts not your own, but using answers for comments muddies things up. And in this case, it's not very obvious what you are referring to or which specific item you are commenting about.davidalger– davidalger2013年05月06日 14:36:10 +00:00Commented May 6, 2013 at 14:36
 
{{block type=".." ..}}into the CMS page content?<block .....><action method="....></action></block>. And as far as I know, this isn't possible with the usual block type definition.