0

I'm using a custom child theme with Luma as the parent, I have a custom page layout xml file and I'd like to include a block that's defined in the parent theme:

<block class="Magento\Theme\Block\Html\Title" name="page.main.title" template="Magento_Theme::html/title.phtml"/>

Adding the above into a <container> in my custom.xml page layout file does nothing, seeing as I'm not looking to modify the parent theme block, do I have to copy title.phtml to my child theme and use that?

If that's the case so be it, but if I can add unmodified parent blocks without duplicating their files that would be ideal, as I have many parent blocks to add to many custom page layouts.

I'm hoping I just need to change the "template" and/or "class" parameters in the code above to achieve this.

Note that my own custom template blocks inside my child theme folder show up as expected in my custom page layouts, so I don't believe I've misidentified this issue.

1 Answer 1

0

As page.main.title is in the default.xml it is already available on every page. To set a new title you need to use a referenceBlock and set the page title via an argument.

<referenceBlock name="page.main.title">
    <action method="setPageTitle">
        <argument translate="true" name="title" xsi:type="string">My own title</argument>
    </action>
</referenceBlock>
2
  • I'm not looking to set a new title actually, I'm just looking to insert this pre-existing parent theme block into a custom page layout xml, even though this block is part of my child theme's default.xml I am unable to add this block into my test.xml page layout. It doesn't show up at all in the DOM. I've tried wrapping it in reference containers, regular containers, etc and nothing does the trick.
    – Sam Assoum
    Commented Feb 11, 2020 at 0:30
  • Does your custom page have a title? Did you set a breakpoint into the title.phtml file to check if its called?
    – CloudySi
    Commented Feb 11, 2020 at 20:18

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.