A very important aspect of Magento theming is the fallback model. Theme inheritance in Magento 2.x has been completely redesigned. The primary upshot of this is that unlimited fallbacks are supported and the default directory is no longer a part of the fallback mechanism.
The fallback order is slightly different for static assets (JavaScript, Less CSS, CSS) and templates, so we'll review both of these cases in detail. Before we explain the fallback order though, we'll need to begin with how parent themes are established in theme.xml.
This is new and central to the new theme fallback model. In any given theme, you have the option of identifying the parent theme. This is done in the theme.xml file, in the root directory of the theme. The following is an example of what text from a sample theme.xml file might look like:
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>Vendor Theme</title>
<parent>Magento/luma</parent>
<media>
<preview_image>media/vendorpreview.jpg</preview_image>
</media>
</theme>As you can see, the parent theme is specified explicitly, and in this case it's the Magento Luma theme. That means that any files not found in the "Vendor Theme" theme will be pulled from the Luma theme. Any files not found there will, by default, be pulled from the Magento "Blank" theme, and if they're not found there, they'll be pulled from the module theme files.
Static assets are content such as JavaScript files, CSS, images, fonts, and Less CSS files. Even though Less CSS files are not, technically speaking, static files, they produce the final CSS, so are categorized as such:
web directory, <theme_directory>/web/imagename.jpg.lib/web/.<module_dir>/view/frontend/web/.<module_dir>/view/base/web/.The fallback mechanism for theme files is simpler, because the module context is always known for them.
<theme_dir>/<Namespace>_<Module>/templates.<parent_theme_dir>/<Namespace>_<Module>/templates.<module_dir>/view/frontend/templates.Here's a pictorial representation of the new fallback model in Magento 2.0. It's a little bit tricky, so we'll walk through each scenario represented here:
theme.xml, and there are no module_override files and there are no static override files. In this case, requests to the theme will fall back to the module theme files.magento_blank, and subsequently the module theme files.theme.xml, and have CSS overrides. In these cases, requests to the CSS will fall back to Vendor_Theme_2, and then Magento_Blank:
The fallback model is a tremendous shortcut for developers. When a new theme is created, it only has to contain those elements that are different from what is provided by the Parent or Module package files. For example, if all parts of a desired site design are similar to the Parent theme, except for the graphic appearance of the site, a new theme can be created simply by adding new CSS and image files to a new theme. Any new CSS files will need to be included in the local.xml file for your theme (we discuss the local.xml file later in this chapter). If the design requires different layout structures, only the changed layout and template files need to be created; everything that remains the same need not be duplicated.
If you're careful not to alter the magento_blank theme and default module theme files, then future upgrades to the core functionality of Magento will not break your installation. You will have access to the new improvements based on your custom design package or theme, making your installation virtually upgrade proof.