2

when we add a block in a CMS page for our multistore now it can only be done like this (I think)

{{widget type="cms/widget_block" template="cms/widget/static_block/default.phtml" block_id="55"}}

We would much rather use somethin like block_name to add blocks - a little more human readable. Can this be done?

Something like

{{widget type="cms/widget_block" template="cms/widget/static_block/default.phtml" block_name="my_handle_fot_this_block"}}

thx

6

Try with

{{widget type="cms/widget_block" template="cms/widget/static_block/default.phtml" block_id="block_identifier_here"}}

This should work because the block widgets calls ->load(block id) and the load method on the block model works with both ids and identifiers.

or

{{block type="cms/block" block_id="block_identifier here"}}
| improve this answer | |
  • Thx Marius. Both dont work: both variables also imply a block_id like a number dont they ? – snh_nl Oct 6 '14 at 14:29
  • Would it be hard to write a quick phtml file that can access a new variable block_name, call it and print it {{widget type="cms/widget_block" template="custom/anyblock.phtml" block_name="block_name_here"}} – snh_nl Oct 6 '14 at 14:30
  • Both of them should work with ids and strings. Just make sure the identifiers exist. – Marius Oct 6 '14 at 14:30
  • cool thx. Ahum. Had to refresh cache because changing of blocks. My bad ;) – snh_nl Oct 6 '14 at 14:35
0

In case when you have custom logic for widgets and don't have cms/widget_block or cms/block as the parent class of your widget there is a trick on how to make it works.

The idea is:

{{widget type="your_module/your_widget_class" template="foo/bar/your_teamplate.phtml" instance_id="XXX"}}

then, implement _beforeToHtml() in your_module/block/your_widget_class and add something like:

/**
 * @inheritDoc
 */
protected function _beforeToHtml()
{
    parent::_beforeToHtml();

    $instanceId = $this->getDataUsingMethod('instance_id');

    if ($instanceId) {
        $widget = Mage::getModel('widget/widget_instance')->load($instanceId);

        if ($widget) {
            $this->addData($widget->getData());
            $this->addData($widget->getWidgetParameters());
        }
    }

    return $this;
}

This trick will load your class and add the ability to render it by playing with instance_id.

Happy coding ;)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.