Recent Posts


Widgets at Magento Imagine Unconference


Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

This entry is part 1 of 2 in the series Posts Inspired by Magento Imagine. Later posts include Magento Security Fix.
If you missed the Unconference at Magento Imagine, I’ve posted my slides, as well as recorded a full screencast of the demo portion of my presentation on the Widgets feature. It’s a two parter, available on YouTube, or embedded below.


During the Q&A I got a question from Boris (of Unirgy fame). I’d been advocating hard that developers make all Blocks intended for end users Widgets. Boris pointed out that doing that means adding an interface like this

class Unconference_Youtubewidget_Block_Youtube extends Mage_Core_Block_Template
implements Mage_Widget_Block_Interface

Because of this, you’d be rendering your Blocks unusable in Magento 1.3. Having some time to think about it now, I’d say a better approach would be to keep your blocks as they are

class Unconference_Youtubewidget_Block_Youtube extends Mage_Core_Block_Template

but then provide an extra block that does nothing but extend your block, and implements the widget interface

class Unconference_Youtubewidget_Block_Youtube_Widget extends Unconference_Youtubewidget_Block_Youtube
implements Mage_Widget_Block_Interface

Another nerdy question/comment came from Jay (of Sweet Tooth) fame. He pointed out you can avoid some of the Widget’s cache invalidation issues by making sure you set a cache key in your Block by issuing something like


from the Block’s _construct pseudo constructor method. This will take care of Block caching, but inserting new Widget Instances will still invalidate your layout cache. Widgets insert Layout Update XML into the database, which gets read in when the Package Layout is created. This means a cached layout won’t get your widget updates, and you’ll need to clear it out. (At least, I think so. The nitty gritty details of the caching engine are one of those systems I haven’t much explored)

Magento Imagine

Imagine was great, and I’ve got a few more posts percolating about the conference. Beyond the official conference, the gathering of all the independent third party developers was the real conference for me. It’s going to be an interesting year in Magento land and that, more than anything else, makes me glad I picked it as a platform.

Originally published February 12, 2011
Series NavigationMagento Security Fix >>

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 12th February 2011

email hidden; JavaScript is required