DEV Community

loading...

Magento 2 theme what is etc/view.xml

Asrar
・1 min read

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>

Discussion (0)

Forem Open with the Forem app