2

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?

Marius
199k55 gold badges431 silver badges837 bronze badges
asked May 3, 2013 at 14:53
3
  • Why don't you put it as a {{block type=".." ..}} into the CMS page content? Commented May 3, 2013 at 15:48
  • Because my block contains action methods. So it has <block .....><action method="....></action></block>. And as far as I know, this isn't possible with the usual block type definition. Commented May 3, 2013 at 16:27
  • What sort of action do you have? Setting a variable or executing bock method? What type of block do you have? Commented May 3, 2013 at 16:45

4 Answers 4

2

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']);
}
answered May 3, 2013 at 16:59
1

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"}}
answered May 3, 2013 at 16:41
1
  • It would work in principle, but I have a LOT of parameters to include, so it wouldn't be practical. Commented May 3, 2013 at 16:45
0

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?

answered May 3, 2013 at 16:38
0

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.

davidalger
7,3061 gold badge31 silver badges47 bronze badges
answered May 6, 2013 at 13:15
1
  • 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. Commented May 6, 2013 at 14:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.