I have create one module for displaying latest product review, module works perfectly and reviews are display on frontend side.

But what I have requirement is admin can select where to display this block on frontend side, either on right sidebar or left sidebar or in main content area.

I have provided dropdown selection for admin to select one layout for display, but on frontend how we can determine which layout to use for display of block, can we put condition in layout xml? Or there is another method to detect?

We can give ifconfig in action tag but its not suitable for my requirement.

What I have do right now is display block in left bar, and block is display in left side bar.

<reference name="left">
<my block />

2 Answers 2


What you have is a widget and you should implement it as such. Widgets have a very handy layout selection interface already made for you.

If you want to implement this without using the widget interface, you need a block method which will set the parent block, e.g.:

protected function _setParentFromSetting($parent = 'left')
    $parent = $this->getLayout()->getBlock($parent);
    if ($parent) {

You would then want to ensure that this method is called when the block is instantiated:

protected function _prepareLayout()
    // logic to read setting
    // e.g. $parent = Mage::getStoreConfig('your/config/path');

    return parent::_prepareLayout();
  • Oh yes we can use widget, but is there someway to achieve without using widget?
    – Mufaddal
    Apr 24, 2013 at 10:20
  • Updated with a workable solution.
    – benmarks
    Apr 24, 2013 at 11:37
  • working with this method $parent->insert($this);
    – Mufaddal
    Apr 24, 2013 at 12:15
  • Great suggestion, a widget is the perfect fit here.
    – philwinkle
    Apr 24, 2013 at 12:18
  • Yes widget is great for this situation, but for this i have to create one widget, but benmarks solution is working fine for me i have add just one condition.
    – Mufaddal
    Apr 24, 2013 at 12:22

There are a number of ways to accomplish what you ask. I'll give you a few here:


An open-source module by Fabrizio Branca/AOE that provides ifconfig/unlessconfig declarations to more than just actions - it extends it to blocks, references.


<reference name="left" ifconfig="your/config/display/left">
     <block type="your/review_block" name="your.review.block" as="review" template="your/template/file.phtml"/>

If you're interested, the module is available here: https://github.com/fbrnc/Aoe_LayoutConditions

Layout Helpers

Create a layout helper which returns the review based on the set configuration value:

<reference name="left">
    <block type="your/review_block" name="your.review.block" as="review" template="your/template/file.phtml">
        <action method="setReview">
            <template helper="mymodule/myhelper/getReviewPosition"/>

Will call the setReview method of your/review_block and pass in the results of:


It is up to you to implement the getReviewPosition and how it returns data, but something like this should get you started:

class Mycompany_Mymodule_Helper_Myhelper extends Mage_Core_Helper_Abstract
   public function getReviewPosition(){
      //get review position configuration settings
          return $review;


This was made more-or-less 'famous' by Alan Storm in this SO thread: https://stackoverflow.com/a/5601579/582138

  • But in helper class how we can set left and right layout for block?
    – Mufaddal
    Apr 24, 2013 at 6:49

Your Answer

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

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