So what is a Magento 2 theme? To understand that, we’ll first need to talk about the Magento_Theme
module.
The Magento_Theme
module contains page layout XML files that define the basic containers for every Magento page layout.
This allows other Magento modules to use layout handle XML files to
- Add frontend assets (JavaScript, CSS, Less) via the
head
element - Add new blocks and containers via layout handle XML files
- Via blocks, add
x-magento-init
anddata-mage-init
javascript apps/widgets - Perform other actions (
<move></move>
, etc.) via layout handle XML files
By itself, all of the above is enough to build a Magento 2 site. Also, thanks to Magento’s infamous flexibility, it would also be possible “theme” – that is, change the appearance of – a Magento system strictly using modules.
However, Magento module programming is not a skill that’s within the grasp of the average interactive agency developer. This became exponentially more true in Magento 2.
The purpose theming in Magento 2 is the simplifying the modification of a Magento site. A theme will allow you to
- Add, or replace, additional translation strings for Magento’s
__
localization function - Specify the height and width for named Magento image assets
-
Replace any front end asset files added by a Magento module
-
Replace any email template file
-
Add files for Magento’s
//@magento_import
LessCSS directive to consume -
Add additional layout handle XML files to merge when Magento merges a specific module’s layout handle XML
-
Override a module’s layout handle XML file
The important take away is this: From a cultural point of view, Magento and traditional PHP CMS developers may think of themes as the way to change Magento’s appearance.
However, from a functionality and engineering point of view, themes are designed to allow less experienced developers to change the behavior of Magento’s core system modules without creating new PHP modules.