문제

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?

도움이 되었습니까?

해결책

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"}}

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top