How does one add a new block and template file to the header in Magento2?

So far I've created a child theme, which is working, including a default.xml, which is successfully moving other block around. But for creating a new block it won't work.

So far I have:

<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <move element="top.links" destination="header-wrapper" before="-" />

    <referenceContainer name="header-wrapper">
        <container name="custom.header" htmlClass="headerSitemenu" htmlTag="div">
            <block class="Magento\Framework\View\Element\Template" name="navigation.sections" before="-" template="Magento_Theme::html/headersitemenu.phtml">


and have created headersitemenu.phtml inside <theme>/Magento_Theme/html.

Flushed and cleaned the cache etc, but nothing shows.

1 Answer 1


wrong template file location it should be in



block name navigation.sections already exist so you can't use change to some other name, block name should be unique. I reckon enable developer mode to get error details. logs are placed in <magento-root>/var/log/* check there you got any error related to invalid template.

if you would like to customize existing block, change <block ..... to <referenceBlock name="navigation.sections">

  • Thanks for catching that! It's still not showing up, but I clearly needed to fix that too! Oct 7, 2016 at 11:33

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.