2

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.

5
  • Turn on template hints in store>configuration>advanced>developer to see what template goes where on the front-end. Jul 6, 2016 at 19:18
  • @Aaron I've used template hints but it doesn't show anything for panel header
    – Nikkawat
    Jul 6, 2016 at 19:39
  • Could you specify what sort of change you want to make to those links? Jul 6, 2016 at 21:38
  • @Aaron I would like to edit the current link names, add some icons and create new links
    – Nikkawat
    Jul 6, 2016 at 21:55
  • You can't do this by simply editing template files. See my answer below. Jul 6, 2016 at 22:57

2 Answers 2

2

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>
-3

Assuming you are not creating a template based off a custom theme, try looking in:

/app/design/frontend/base/default/template/page/html/header.phtml

Note: This is based off my knowledge of 1.X, not sure of changes since 2.X

2
  • Yea I thought it would be in header.phtml but it has contents to populate the panel header div
    – Nikkawat
    Jul 6, 2016 at 19:37
  • Magento 2 is not like magento 1 in the way that it builds its elements, the header is built with knockoutjs and not a .phtml file.
    – andy jones
    Jan 25, 2017 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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