Layout Handle Priority in Magento 2

layoutmagento2update-handlexml

It seems that in magento 2 the cms_page_view layout handle has a higher priority then then the cms_index_index layout handle. (wich seems very illogical)

The scenario is that for all the cms pages I want to place the page.main.title element in a different container then standard and I use a diffrent template file for it. With the exception of the home page where I want it in yet another container.

So in Magento_Cms module I placed the following layout update in cms_page_view.xml

<referenceBlock name="page.main.title" template="html/cms-subtitle.phtml" />
<move element="page.main.title" destination="cms.page.title" after="-" />

then in the Magento_Theme module i placed the following layout update in cms_index_index.xml

<referenceBlock name="page.main.title" template="html/title.phtml" />
<move element="page.main.title" destination="content.container" before="-"/>

In the cms_index_index I can't seem to interact with the page.main.title anymore the above code doesn't work. I also try'd to remove it but also no success. Creating a new instance of the title.phtml will result in the block giving me the meta_title instead of the content heading so that's not an option either.

Does anybody have an idea how I can move the page.main.title to the content.container on the homepage? Is there maybe a layout handle I don't know about that does work?

Best Answer

There is a layout handle that overrides the cms_page_view and that's the cms_index_index_id_home (where 'home' is the id for my homepage) so i ended up moving the conflicting layout updates from cms_index_index to cms_index_index_id_home.