3

I have a few custom modules (content sliders etc) that have their own config sections in System->Configuration. I'd like to be able to add custom layout updates that would apply to the pages these sliders are added to via the admin, instead of a local.xml file (or module xml) - the same way you can for cms pages and categories etc:

Layout Update XML

I see that the cms pages use the following (in app/code/core/Mage/Cms/Helper/Page.php):

    $action->loadLayoutUpdates();
    $layoutUpdate = ($page->getCustomLayoutUpdateXml() && $inRange)
        ? $page->getCustomLayoutUpdateXml() : $page->getLayoutUpdateXml();
    $action->getLayout()->getUpdate()->addUpdate($layoutUpdate);
    $action->generateLayoutXml()->generateLayoutBlocks();

...so I guess it would be something similar to that. Is it possible to do this for a custom module? And if so, any general pointers on how to accomplish it?

2

I have done that customization for AheadWorks blog once . You can try to adjust this to fit your code.

First add custom_layout_update database field for your entity. I did following to add that for blog post using sql installer:

$installer = $this;
$installer->startSetup();
$installer->run("ALTER TABLE {$this->getTable('blog/blog')}
    ADD `custom_layout_update` text NOT NULL;
");
$installer->endSetup();

Then in blog post edit form I've added field which lets me to save layout update.

Finally I replaced code in renderPage() method which loads layout. I removed this one:

$action->loadLayout();

And added following:

$action->getLayout()->getUpdate()->addHandle('default');

$action->addActionLayoutHandles();
$action->loadLayoutUpdates();

if (strlen($page->getCustomLayoutUpdate())) {
    $action->getLayout()->getUpdate()->addUpdate($page->getCustomLayoutUpdate());
}

$action->generateLayoutXml();
$action->generateLayoutBlocks();

That part inside if condition does the trick, rest around comes from loadLayout() method.

In AheadWorks Blog extension renderPage() method is placed in helper class and it's called in controller. Usually this layout code is being called directly in controller, so you may look in your controller code for that.

| improve this answer | |
1

I'm not sure you can achieve this using the system->configuration settings.
I mean you can, but you have to load the layout update before any output is generated.
I assume your sliders are used like {{block type=....}} or {{widget type=...}} in cms pages or blocks.
If that is the case, then you cannot load your layout update from system->configuration, because at the time the {{}} directives are parsed the layout handles is already loaded and you cannot add any more handles to it.

If you have separate pages for the sliders and you know in the controller that you are going to use a specific handle you can do the same things as the cms pages do.

$configLayoutUpdate = Mage::getStoreConfig('path/to/update');
$action->loadLayoutUpdates();
if ($configLayoutUpdate) {
    $action->getLayout()->getUpdate()->addUpdate($configLayoutUpdate);
}
| 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.