I have two products sliders
(based on \Magento\Catalog\Block\Product\Widget\NewWidget
) on my homepage.
I would like to add swatches to these product sliders.
The sliders are added in my homepage.xml layout as below:
<container name="items.wrapper.slider" after="full.width.white.bar" htmlTag="div"
htmlClass="wrapper wrapper--large c-catalog__products--slider-wrapper">
<block class="Silvan\TestExtension\Block\Product\Widget\NewWidget"
template="Magento_Catalog::product/widget/new/content/new_grid.phtml" name="new.products">
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="new.products.swatches" template="Magento_Swatches::product/listing/renderer.phtml" />
</block>
</container>
I've tried to add the swatches by adding the block with class Magento\Swatches\Block\Product\Renderer\Listing\Configurable
but this doesn't work as expected.
Does anyone know how to achieve this in homepage?
Thanks.
Best Answer
Create simple module for display swatches in configurable product in homepage.
You have to follow below steps to get swatches on homepage product collection,
app/code/Test/Homeslider/registration.php
app/code/Test/Homeslider/etc/module.xml
app/code/Test/Homeslider/view/frontend/templates/products.phtml
create xml file for display inside homepage, app/code/Test/Homeslider/view/frontend/layout/cms_index_index.xml
Create Block file, app/code/Test/Homeslider/Block/Productslist.php
Run command,