Question

As from official docs :

base : used for both front end and admin html.

  1. As the part of Magento Theming, how and when to use base folder and how the fallback work with base folder.
  2. As i observed in the modules, we are using base, for example \vendor\magento\module-wishlist\view\base\layout\catalog_product_prices.xml

  3. As of my knowledge both( Module & theme level) are for overriding, but how Magento 2 will handle the fallback logic for final rendering or merging the changes.

Knowledge sharing will be appreciated.

Was it helpful?

Solution

Source

base folder it's default fallbacks for all area and used to share resources across of areas

Fallback sequence

  1. <current_theme_dir>/<Namespace>_<Module>/layout/
  2. <parent_theme(s)_dir>/<Namespace>_<Module>/layout/
  3. <module_dir>/view/frontend or adminhtml/layout/
  4. <module_dir>/view/base/layout/

Magento layout processing

  1. Collects all layout files from modules. The order is determined by the modules order in the module list from app/etc/config.php.
  2. Determines the sequence of inherited themes [<parent_theme>, ..., <parent1_theme>] <current_theme>
  3. Iterates the sequence of themes from last ancestor to current:

    a. Adds all extending theme layout files to the list.

    b. Replaces overridden layout files in the list.

  4. Merges all layout files from the list.


Custom module only extends the core layout file.

Namespace/Moduelname/view/frontend/layout/catalog_product_view.xml

means you are extending product page into your module.

where as

app\design\frontend\<Vendor>\<theme>\Module_Vendor\layout\override\base\catalog_product_view.xml

here you are overriding the core layout.

then according to Magento layout processing if you are overriding layout in theme it will replace also extended layout (in custom module ).

OTHER TIPS

The base folder is an area to share for front-end representation logic (less, js, images, layout etc.), the resource which is for both admin and front-end, you can keep those files in the base folder.

For Example:

view/base/web/js/library.js which you are using in both for admin and front-end in this case you have should keep that library file on the base folder.

find the flowchart for fallback mechanism:

enter image description here

source [Click here][2]

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top