2

I'm creating a widget to display ratings. (Already created -> activated -> added in a page)

Calling this widget by {{widget type="widgetreviewtab/list"}} on a cms page named sample

Now when access http://site.com/custom.html it's empty.

Below is my WidgetReviewTab/Block/List.php where i'm trying to get rating lists.

class Review_WidgetReviewTab_Block_List extends Mage_Core_Block_Abstract implements Mage_Widget_Block_Interface
{
    protected function _toHtml()
    {        
        $html = $this->getChildHtml('review_list');
        return $html;
    }

}

If i use $html = 'custom text'; i'm getting result as custom text so widget's function is fine.

Is it proper to call $this->getChildHtml('review_list'); in widget.

I think i'm missing something ? Did any one have any idea to make it work ?

5
  • 1
    Do you have child block review_list defined in layout xml for Review_WidgetReviewTab_Block_List? If not you need to define it. – oleksii.svarychevskyi Feb 26 '14 at 12:00
  • No i'm not. I'm a newbie to magento. Can you plz elaborate the process. – Vinoth Feb 26 '14 at 12:05
  • Can you describe in question how you call your Review_WidgetReviewTab_Block_List block? – oleksii.svarychevskyi Feb 26 '14 at 12:06
  • Description got updated. Have a look – Vinoth Feb 26 '14 at 12:13
  • Do you want to display a list of all reviews or only for particular product? – oleksii.svarychevskyi Feb 27 '14 at 17:01
1

Widgets are independent entities apart from the whole layout XML system. So calling the $this->getChildHtml() method, which depends on layout XML, will not work in this case.

When you use $this->getChildHtml('review_list') that actually means that somewhere in the layout XML a 'review_list' block is defined as a child of the current block. That is not the case here, so lets forget the getChildHtml for now.

When you create a widget in the content through a widget directive, thats the {{widget..}} thingy you already talked about in your question, it is being parsed by a template filter.

This means that all logic for building up the content should be present in the Review_WidgetReviewTab_Block_List. A proper widget also needs a widget.xml in your module. In this xml file you can configure default settings but also define for instance which template should be used to render your widget. I attached a example at the bottom of my answer.

Displaying ratings of any kind means you probably need to load a helper or model via your widget block to get the needed data from the database.

A good tutorial to start building widgets: https://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-magento-widget-part-1

Widget example:

<?xml version="1.0"?>
<widgets>
   <example type="review_widgetreviewtab/list">
       <name>Widget name</name>
       <description>Widget descriptoin</description>
       <parameters>
           <some_setting>
            <label>Setting name</label>
            <required>1</required>
            <visible>1</visible>
            <value>1</value>
            <type>text</type>
        </some_setting>
        <template>
            <required>1</required>
            <type>select</type>
            <value>widgets/my_widget_template.phtml</value>
        </template>
    </parameters>
</example>

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.