1

how to override the color navigation swatch in magento 2 my code is in below but it is not working

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
    <css src="Magento_Swatches::css/swatches.css"/>
</head>
<body>
    <referenceBlock name="category.product.type.details.renderers">
        <block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" name="category.product.type.details.renderers.configurable" as="configurable" template="Mycustom_MultipleLayeredNavigation::layer/renderer.phtml" ifconfig="catalog/frontend/show_swatches_in_product_list" />
    </referenceBlock>
</body>

enter image description here

1
  • do you find any solution for this, i m also facing a same one May 31 '19 at 5:14
1

You can try below code, please put the file at:

app/design/frontend/{{Yourpackage}}/{{Yourtheme}}/Magento_Swatches/templates/product/layered/renderer.phtml

Or you can create custom module and follow below steps:

  1. create a folder view/frontend/layout/catalog_category_view.xml and put below code inside that:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="category.product.type.details.renderers.configurable">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Your_module::path/to/yourtemplate.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>
  1. Create the custom template with required customization as per the given path (its path/to/yourtemplate.phtml).
5
  • which xml file should i call to override color navigation in magento2 Oct 23 '18 at 6:58
  • You can add this updates in custom module's catalog_product_view.xml file. I hope you are trying to update it at product view page. Oct 23 '18 at 6:59
  • If it is not exist already, then create new xml file at your/module/view/frontend/layout/catalog_product_view.xml Oct 23 '18 at 7:00
  • i want to override in in product listing page Oct 23 '18 at 7:06
  • Then you need to create catalog_category_view.xml if it is not available.. @Hit's answer should work properly if you are following those steps properly.. Oct 23 '18 at 9:01
0

You can create file under:

app/code/Vendor/Modulename/view/frontend/layout/catalog_category_view.xml

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="category.product.type.details.renderers.configurable">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Modulename::product/layered/renderer.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Set your templae file at below location :

app/code/Vendor/Modulename/view/frontend/templates/product/view/type/options/configurable.phtml
0

If you want to override phtml files only then you can do with your custom theme as well.

  1. Copy core file(renderer.phtml) from below path.

vendor/magento/module-swatches/view/frontend/templates/product/layered/renderer.phtml in magento

  1. Ex : Add above core file(rendered.phtml) to your custom theme

app/design/frontend/Yourcompany/Yourtheme/Magento_Swatches/templates/product/layered/

  1. Add your custom code in above file.
0

try below code from

vendor/magento/module-swatches/view/frontend/layout/catalog_category_view.xml

create a new file into

app/design/frontend/Customtheme/default/Magento_Swatches/layout/catalog_category_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>        
        <referenceBlock name="category.product.type.details.renderers"><!-- category.product.type.details.renderers means your core referenceBlock name-->
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Mycustom_MultipleLayeredNavigation::layer/renderer.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

run command

php bin/magento cache:clean && php bin/magento cache:flush

OR

try with re-deploy to content

php bin/magento setup:upgrade && php -dmemory_limit=6G bin/magento setup:static-content:deploy -f

3
  • which xml file should i call to override color navigation in magento2 Oct 23 '18 at 6:58
  • please check my updated answer
    – Hitesh
    Oct 23 '18 at 7:02
  • its not working Oct 23 '18 at 7:13

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.