DEV Community

Asrar
Asrar

Posted on

1 1

Magento 2 theme what is etc/view.xml

In this file, frontend related properties can be configured i.e. size of product images. Also a custom ID of image can be added here with its size and then this image can be generated in PHP.

Additionally, some properties can be set without overriding template files :

<vars module="Magento_ConfigurableProduct">
<var name="gallery_switch_strategy">replace</var>
</vars>

Now, in vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml, the variable gallery_switch_strategy is fetched like

<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy', 'Magento_ConfigurableProduct') ?: 'replace'; ?>

So, instead of overriding a template file, we can use theme's etc/view.xml.

Theme's etc/view.xml can be used to exclude any js file, any js components or a complete directory containing static assets from bundling, like below :

<exclude>
<!-- js file -->
<item type="file">Lib::jquery/jquery.min.js</item>
<!-- Catalog level : js component -->
<item type="file">Magento_Catalog::js/zoom.js</item>
<!-- Dir level : exclude bundling for any static contents -->
<item type="directory">Lib::modernizr</item>
<item type="directory">Lib::tiny_mce</item>
<item type="directory">Lib::varien</item>
<item type="directory">Lib::jquery/editableMultiselect</item>
<item type="directory">Lib::jquery/jstree</item>
<item type="directory">Lib::jquery/fileUploader</item>
<item type="directory">Lib::css</item>
<item type="directory">Lib::lib</item>
<item type="directory">Lib::mage/backend</item>
</exclude>

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay