I understand that in my module/view/frontend/layout folder, if I create a file called social_index_index.xml this file will refer to a controller located at Social/Controller/Index/Index.php.

However I currently was looking in the vendor/magento/module-catalog/view/frontend/layout folder and I saw a few files with longer names such as catalog_category_view_type_default.xml and catalog_category_view_type_default_without_children.xml.

What controllers do these files refer to when they are longer names? I do not see a path to a controller for these anywhere.


Looks like you're getting a bit confused with handles, specifically how Magento utilises them.

You referred initially to social_index_index.xml. This is actually loaded because in layout there was a handle added - social_index_index. This would have come from the auto generated handle formed from the route name, controller name and action name that was then added as a layout handle (this is formed here and actually added as a handle here).

What you're looking at with catalog_category_view_type_default.xml is another layout XML file that would be loaded when catalog_category_view_type_default is a present handle. This would happen in a category that is not an anchor (no layered navigation) and would have been caused by this code in the category view controller.

Another good example to demonstrate this is the default handle. How come default.xml layout files always apply? Well, Magento leverages handles just like both examples above. You can see the handle added here

So handles will load layout XML files with the same identifier (social_index_index -> layout files named social_index_index.xml apply). You could add your own handles (there are many way and places you could do that) and that would get included (catalog_category_view_type_default added by some logic -> layout files named catalog_category_view_type_default.xml apply)

This explanation skips over alot but you seem to have at least a basic understanding of layout so hopefully this all makes sense to you!

  • The thing I am still not understanding though is, if I create an xml file at app/code/Module/Social/view/frontend/layout/social_index_index.xml, the controller at Social/Controller/Index/Index.php will be called. However, with the catalog_category_view_type_default.xml file, there is no file path to a controller. Does this not have a controller? Maybe its an arbitrary handle? – Metropolis Oct 12 '17 at 14:53
  • Yes exactly, it is almost arbritrary. The point is all of them are the same, they're just a handle. In reality, the only difference is that one (social_index_index) is auto generated by Magento App logic and the other is added specifically by the category view controller (catalog_category_view_type_default) in its controller code – Josh Davenport Oct 12 '17 at 14:55
  • Don't try to think of them as different because they're not different. They're both handles. The thing to realise is that handles can be added by code anywhere, some of them are automatically generated and others are added in the logic laid out by other code (i.e. is this category layered or not?) – Josh Davenport Oct 12 '17 at 14:58
  • Okay so one more question. Does catalog_category_view_type_default handle call to the modules-catalog/Controller/Category/View.php class? Or does it just not have a controller at all and is just called by other handles? Also, is it possible to have a layout file with just one or two names instead or three or more? – Metropolis Oct 12 '17 at 15:04
  • Handles don't call to anything or necesarilly equate to anything either. Some represent the current route_controller_action (as in the second paragraph), others based on logic (third para) others arbritrarily (fourth para). There is no reason why a handle has to equate to a class so that doesn't really make sense. modules-catalog/Controller/Category/View.php happens to add the catalog_category_view_type_default handle to the stored list of handles. Other code adds other handles for a multitude of reasons – Josh Davenport Oct 12 '17 at 15:08

Metropolis first,first,you need understand how this files are merge in the page.

In the magento2, all the layout files name in equivalent to its Layout Handler name and those handles are automatically include at respective page and call those handle's xml add via Magento own logic

just like: social_index_index is a handler which is same page full Action name of that page,which create during page under

Some layout files which is not related equivalent handle name which is included at page via other handler related layout file using <update handle="[NonHandlerLayoutfile.xml]"/>

An example:

vendor/magento/module-sales/view/adminhtml/layout/sales_order_edit_index.xml of module sales order admin edit page.

  • Sorry, I am having a hard time understanding what you are saying here. – Metropolis Oct 11 '17 at 19:35
  • I will explain briefly at tomorrow – Amit Bera Oct 11 '17 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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