skip to Main Content

I want to make a new div and assign it data which I getting in list.phtml file . Like I am getting reviews block in my xml reference block file like this

<referenceBlock name="product.info.details" >
            <block class="MagentoReviewBlockProductReview" name="reviews.tab" as="reviews" template="Magento_Review::review.phtml" group="detailed_info">
                <block class="MagentoReviewBlockForm" 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>

and my list.phtml file is like

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

Now I want to assign same functionality to a new div on magento2 product page. What I should do to assign this functionality to a new div

2

Answers


  1. First, make reference container then move block within reference container.

    <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"  />
    
    Login or Signup to reply.
  2. Please use this code-

    <referenceContainer name="page.wrapper">
        <container name="customcontainer.product.view" htmlTag="div" htmlClass="customcontainer.product.view" >
    
        </container>
    </referenceContainer> 
    
    
    <move element="product.info.details" destination="customcontainer.product.view"  />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search