how to display review form as well as reviews in a tab in product page [duplicate]

旧城冷巷雨未停 提交于 2019-12-04 21:43:01

This is how I handled this situation in one of my projects:

Add tab with reviews

<block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml" >
    <action method="addTab" translate="title" module="catalog"><alias>tab_review_list</alias><title>Product Reviews</title><block>review/product_view_list</block><template>catalog/product/view/tabs/reviews.phtml</template></action>
</block>

Now, the review form is handled by the different type of block which normally is a sub-block of review page. There is no way to make nested block with addTab action but you can use <reference> handler after creating review block in tabs like this:

<reference name="tab_review_list">
  <block type="review/form" name="tab_review_form" as="review_form" template="catalog/product/view/tabs/review_form.phtml" />
</reference>

name in <reference> handler must be equal to what is in <alias> in addTab action

And in catalog/product/view/tabs/reviews.phtml you just use

    echo $this->getChildHtml('review_form');

You can use <reference> handler to add more block to review list and review form.

Of course, you have to create files for review list and review form in the paths entered in template argument, so in this case you would need to create catalog/product/view/tabs/reviews.phtml and catalog/product/view/tabs/review_form.phtml. You can change review form template to the default one review/form.phtml if you do not need change the code there or you will be using it only in that tab but review list might need more changes in html structure so it is good idea to create separate file for it and use parts of the default code as needed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!