1

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?

2

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.

  • Does this work for any CMS Page? Like cms_index_index_1.xml for CMS page with ID 1? I can't seem to get it working or read about this anywhere – harri Aug 31 '17 at 9:20
  • Ok i got it to work just exactly as you said but only seems to work for home. – harri Aug 31 '17 at 9:31
  • It should indeed work for all the cms pages, but you can't use the id number you need use url key. so it should be like this: cms_index_index_id_{url key} so if you make a page called "About us" with the url key "about-us" it would be cms_index_index_id_about-us hope it helps :) – Pascal Wientjes Sep 1 '17 at 9:58
  • Thanks for getting back to me, i did try that i didn't have any luck however with URL key i shall try again however. – harri Sep 1 '17 at 10:11

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.