我想创建一个新的 div 并为其分配在 list.phtml 文件中获取的数据。就像我在 xml 引用 block 文件中得到评论 block 一样
<referenceBlock name="product.info.details" >
<block class="Magento\Review\Block\Product\Review" name="reviews.tab" as="reviews" template="Magento_Review::review.phtml" group="detailed_info">
<block class="Magento\Review\Block\Form" name="product.review.form" as="review_form">
<container name="product.review.form.fields.before" as="form_fields_before" label="Review Form Fields Before"/>
</block>
</block>
</referenceBlock>
我的list.phtml
文件就像
<?php
/**
* @description:
*
*/
?>
<?php
$_items = $block->getReviewsCollection()->getItems();
$format = $block->getDateFormat() ?: \IntlDateFormatter::SHORT;
?>
<?php if (count($_items)):?>
<div class="block review-list" id="customer-reviews">
<div class="block-title">
<strong><?php /* @escapeNotVerified */ echo __('Customer Reviews') ?></strong>
</div>
<div class="block-content">
<div class="toolbar review-toolbar">
<?php echo $block->getChildHtml('toolbar') ?>
</div>
<ol class="items review-items">
<?php foreach ($_items as $_review):?>
<li class="item review-item" itemscope itemprop="review" itemtype="http://schema.org/Review">
<div class="review-title" itemprop="name"><?php echo $block->escapeHtml($_review->getTitle()) ?></div>
<?php if (count($_review->getRatingVotes())): ?>
<div class="review-ratings">
<?php foreach ($_review->getRatingVotes() as $_vote): ?>
<div class="rating-summary item" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
<span class="label rating-label"><span><?php echo $block->escapeHtml($_vote->getRatingCode()) ?></span></span>
<div class="rating-result" title="<?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%">
<meta itemprop="worstRating" content = "1"/>
<meta itemprop="bestRating" content = "100"/>
<span style="width:<?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%">
<span itemprop="ratingValue"><?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%</span>
</span>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="review-content" itemprop="description">
<?php echo nl2br($block->escapeHtml($_review->getDetail())) ?>
</div>
<div class="review-details">
<p class="review-author">
<span class="review-details-label"><?php /* @escapeNotVerified */ echo __('Review by')?></span>
<strong class="review-details-value" itemprop="author"><?php echo $block->escapeHtml($_review->getNickname()) ?></strong>
</p>
<p class="review-date">
<span class="review-details-label"><?php /* @escapeNotVerified */ echo __('Posted on') ?></span>
<time class="review-details-value" itemprop="datePublished" datetime="<?php /* @escapeNotVerified */ echo $block->formatDate($_review->getCreatedAt(), $format) ?>"><?php /* @escapeNotVerified */ echo $block->formatDate($_review->getCreatedAt(), $format) ?></time>
</p>
</div>
</li>
<?php endforeach; ?>
</ol>
<div class="toolbar review-toolbar">
<?php echo $block->getChildHtml('toolbar') ?>
</div>
</div>
</div>
<?php endif;?>
现在我想将相同的功能分配给 magento2 产品页面上的新 div。我应该做什么来将此功能分配给新的 div
最佳答案
首先,创建引用容器,然后在引用容器内移动 block 。
<referenceContainer name="page.wrapper">
<container name="extra.product.view" htmlTag="div" htmlClass="extra.product.view" >
<container name="extra.product.view.container" htmlTag="div" htmlClass="custom-product-detail-section">
</container>
</container>
</referenceContainer>
<move element="product.info.details" destination="extra.product.view.container" />
关于magento - 如何在magento2中将数据分配给新的div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46195082/