Magento – Magento 2 – Location of .phtml containing page header

magento2template

I'm creating a custom template and am trying to figure out which .phtml needs to be extended so I can edit the page header. I would like to edit the links: Sign in or Create an Account.

Using the debug template path hints, I don't see a .phtml that encompasses the page header unlike subscribe.phtml for the footer/subscribe/newsletter and copyright.phtml for the copyright banner.

=======

EDIT: Used PhpStorm to recursively search the entire project for the text 'panel wrapper' and it was found in:

public_html/vendor/magento/theme-frontend-blank/Magento_Theme/layout

  • line 11 of default.xml

However, in my template's composer.json I have 'magento/theme-frontend-luma' in the require field.

Best Answer

Unfortunately there's no easy way to do it. Those elements are not coming from a template, they are generated by block classes in the Magento_Customer module.

The easiest way to do this that I've found would be to make a module with a custom block, template, and default.xml layout. You'd remove the 'header.links' block and then insert your own block and template. You would just need your block class to contain the logic to display which links depending on whether customer is logged in.

To remove the existing block and insert your own, just add the following code to your default.xml within the body tag:

<referenceBlock name="header.links" display="false"/>

        <referenceContainer name="header.panel">
            <block class="Me\MyModule\Block\MyBlock" template="Me_MyModule::mytemplate.phtml" name="top.mylinks"/>
        </referenceContainer>
Related Topic