0

I try to add Size Chart block on product view page in Magento 2. I add this code in catalog_product_view.xml

<referenceContainer name="product.info.main">
    <block class="Magento\Catalog\Block\Product\View\Attributes" name="sizechart" template="product/view/sizechart.phtml"/>
</referenceContainer>

and this in the sizechart.phtml

<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
?>
<?php if ($_product->getData('size_chart')): ?>
    <a href="#">Size Chart</a>
       <?php 
       echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId($_product->getAttributeText('size_chart'))->toHtml();?>
<?php endif; ?>

Everything is okay for the simple products, but when I open a configurable product the size chart block in not displayed anymore.

What is the problem?

Thanks

0

Try adding the following code, this may help you.

<referenceContainer name="product.info.main">
    <block class="Magento\Catalog\Block\Product\View\Attributes" name="sizechart" template="product/view/sizechart.phtml" after="-" />
</referenceContainer>

Try static-content deploy and cache flush commands.

  • is not work, I think there we need to add an if statement to the block – Robert Nov 1 '18 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.