Please note this question is about the yet-to-be-released Magento 2, which I'm still trying to get to grips with.

Each module contributes to each layout handle separately. For example, the default handle is made up of these files:



The base files come first followed by frontend files, followed by a number of themes. I would like to know which order those in frontend are used. I think Magento/Theme/... must be first because many others make references to it's blocks, be it adding, moving or removing.

I considered they might be following dependency order but that isn't adequate because there are many circular dependencies. For example, Magento_Customer depends on Magento_Theme as you would expect, but Magento_Theme also depends on Magento_Customer. If the wrong order is followed then important customer blocks would not be shown.

By setting breakpoints I've worked out the files are not loaded in any particular order, they are just dumped into a merged DOM to be dealt with later. But I cannot tell what happens to the merged data afterwards, is it some kind of magic?

1 Answer 1


Modules are sorted based on their sequence dependencies. The module with the least dependencies comes first, any module with a <sequence> dependency should be loaded after any of the modules declared in the sequence block.

Module Sorting Logic

Layout File Sorting Decorator

Layout Merge Logic

Dependency Injection of Decorator

Once the XML files are merged, there is more logic for how the different elements are processed. First all the elements are read and updated, then all the moves are processed, and finally the removal of any blocks is processed.

Logic for Processing Nodes

  • "is guaranteed" - unfortunately it is not guaranteed due to a few bugs, but yea, at least this is the idea! :-) Welcome to Magento Stackexchange! May 20, 2014 at 17:10
  • Excellent use of source code. I was looking at some of those links specifically and noticed that <depends> and <sequence> are treated equally. That is, they are merged into the same $moduleData['dependencies'] array so how are they distinguished? May 20, 2014 at 18:26
  • Also, I accept this answer because it tells me what I needed to know. My module(s) must declare it's dependencies appropriately for it's layouts to work. May 20, 2014 at 18:28
  • @FabianBlechschmidt maybe "guaranteed" is too strong a word and I should edit my answer. Still learning the rules of StackExchange. May 20, 2014 at 18:46
  • @clockworkgeek I'm not sure that they are treated equally. The nodes under <sequence> will be added to $moduleData['dependencies']['modules'] while those under <depends> get added to $moduleData['dependencies']['extensions']. Right now at least, the module dependencies are being used for the sort, not the extension dependencies. May 20, 2014 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.