2

I added my custom product list in detail page, the collection is properly displaying but now I want to display swatches in that list. is there any way to make it possible?

1 Answer 1

2

Put below code in your referenceblock in XML file.

<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable"
     name="category.product.type.details.renderers.configurable"
     template="Magento_Swatches::product/listing/renderer.phtml"
     ifconfig="catalog/frontend/show_swatches_in_product_list">
        <arguments>
            <argument name="configurable_view_model"
                xsi:type="object">Magento\Swatches\ViewModel\Product\Renderer\Configurable</argument>
        </arguments>
</block>

Put below code in your phtml file.

$blocks = $this->getLayout()->getBlock('category.product.type.details.renderers.configurable');
echo $blocks->setProduct($_item)->toHtml();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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