且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在产品查看页面上添加评论选项卡

更新时间:2023-12-02 09:03:10

这是我来自这是我在其中一个项目中处理这种情况的方式:

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

添加带有评论的标签,

<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>

现在,审阅表单由不同类型的模块处理,该模块通常是审阅页面的子模块.无法通过addTab动作制作嵌套块,但是可以在如下所示的选项卡中创建审阅块之后使用<reference>处理程序:

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>

<reference>处理程序中的

name必须等于addTab动作中<alias>中的内容.

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

catalog/product/view/tabs/reviews.phtml中,您只需使用

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

您可以使用<reference>处理程序向查看列表和查看表单添加更多块.

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

当然,您必须在template参数中输入的路径中创建用于审阅列表和审阅表单的文件,因此在这种情况下,您将需要创建catalog/product/view/tabs/reviews.phtmlcatalog/product/view/tabs/review_form.phtml.您可以将审阅表单模板更改为默认的review/form.phtml.如果您不需要在那里更改代码,或者仅在该选项卡中使用它,但是审阅列表可能需要对html结构进行更多更改,因此***创建单独的表单文件并根据需要使用部分默认代码.

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.