We launched a new site. Please contact us if you run into a problem. See known issues.

Getting the most out of Magento 2's view.xml

The power of the view.xml file in Magento is perhaps too often overlooked. You likely deal with it on the occasions when you track a particular presentation element you want to change there. But have you considered creating new configurable presentational elements to utilize it?

Every module can define a view.xml, and the file of the same name in your theme can override any variables or media settings defined this way. So when you’re implementing functionality with an interface layer …

… give some consideration to what major presentational decisions might make sense to include some configuration for.

The above example just requires fetching the config view model with \Magento\Framework\View\ConfigInterface and some initial values in view.xml.

Now there’s some presentational flexibility that can be managed in the theme with the flip of some XML, rather than by modifying or overriding templates.

Chris Nanninga

Director of Training and Development at SwiftOtter -@ChrisNanninga