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
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();