【发布时间】:2012-01-26 23:39:33
【问题描述】:
我正在更改 Magento 1.5 网站的前端布局,我正在尝试将我的产品评论从单独的页面移动到下方的“更多信息”选项卡之一目录中的产品页面。因此,我想让这个标签的内容有条件 - 我希望标签在现有评论存在时显示它们,但在产品还没有评论时显示评论创建表单。
这是我迄今为止尝试过的,我正在尝试组合的部分。
/app/design/frontend/our-site/default/review.xml:
<catalog_product_view translate="label">
<label>Catalog Product View</label>
<reference name="product.info.tabs">
<action method="addTab" translate="title" module="review">
<alias>product.reviews</alias>
<title>Reviews</title>
<block>review/form</block>
<template>review/form.phtml</template>
</action>
</reference>
</catalog_product_view>
此 XML 会导致“留下您的评论”表单显示在产品页面上名为“评论”的选项卡下。
我在/app/code/core/Mage/Catalog/Block/Product/View/Tabs.php 中找到了'addTab 函数,我可以看到它是如何工作的。但是,我认为我没有看到一种方法可以使用 XML 来决定页面上应该显示的内容。
我注意到summary.phtml 文件做了我想要的事情:它有:
if ($this->getReviewsCount()): ?>
<div class="ratings">
<?php if ($this->getRatingSummary()):?>
<div class="rating-box">
<div class="rating" style="width:<?php echo $this->getRatingSummary() ?>%"></div>
</div>
<?php endif;?>
<p class="rating-links">
<a href="<?php echo $this->getReviewsUrl() ?>"><?php echo $this->__('%d Review(s)', $this->getReviewsCount()) ?></a>
<span class="separator">|</span>
<a href="<?php echo $this->getReviewsUrl() ?>#review-form">
<?php echo $this->__('Add Your Review') ?></a>
</p>
</div>
<?php elseif ($this->getDisplayIfEmpty()): ?>
<p class="no-rating">
<a href="<?php echo $this->getReviewsUrl() ?>#review-form">
<?php echo $this->__('Be the first to review this product') ?>
</a>
</p>
<?php endif; ?>
看起来它有条件函数'如果有评论则执行此操作,如果没有评论则执行其他操作。如何在渲染链的早期调用它来决定渲染到页面中的块的上下文是什么?这是需要在 XML 部分的 phtml 部分完成的任务吗?
【问题讨论】:
标签: php xml magento magento-1.5 frontend