I'm having issues with Magento 2 missing out my header and footer, which are custom modules setup in my custom theme. They display correctly locally, on a MAMP set-up. However, on my staging server, I get the following error:

Invalid template file: 'magicheader.phtml' in module: 'MagicPack_Magicheader' block's name: 'MagicPack_magicheader'

This is coming from my default.xml file:

<block class="MagicPack\Magicheader\Block\Magicheader" name="MagicPack_magicheader" template="magicheader.phtml">

And my class is declared in:


Where I declare it as:

namespace MagicPack\Magicheader\Block;
class Magicheader extends \Magento\Framework\View\Element\Template
    public function _prepareLayout()
        return parent::_prepareLayout();

The file itself is in:


I'm going a little crosseyed trying to work out why this is deemed invalid on the server and not locally. We're running 5.6 on both environments. Any assistance will be greatly appreciated.

Let me know if more info is needed.

Edited based on suggestions to map the correct cases to class names.

Could someone confirm my naming conventions are correct here?

  • I assume that a problem in the MAMP, your file-/folder-names and the autoloader. Commented Apr 22, 2016 at 17:42
  • Do you mean related to case sensitivity? Do you know the correct case that I should be using? Commented Apr 22, 2016 at 18:38
  • Did you delete both var/cache and var/generation ? Commented Apr 23, 2016 at 6:10
  • Yes I did. Definitely cleared all caches. Commented Apr 23, 2016 at 10:01

4 Answers 4


I have resolved this issue now. The problem was the name of the view folder:


This needed to be:


With a small case "v".

Hope that helps someone in the future.

  • 1
    Ahaha, I had the similar problem with my FED collegue, which works on Windows without case sensitive problems. But his custom theme could not work in Linux.
    – goral
    Commented Apr 23, 2016 at 16:34
  • 3
    In my case, i've used "template" instead for "templates" :) Hope this help some one.
    – fudu
    Commented Sep 22, 2018 at 3:11
  • Hahaha.. Same problem bro Forgot to check the module name. After 1hrs search found this..
    – Ask Xah
    Commented Jul 22, 2019 at 8:12
  • I was also going crazy until I found I had template folder name singular :(. After renaming to templates the issue was fixed. Commented Oct 18, 2019 at 3:15
  • Noooooooo!!!! Why won't it read?!?!?! I'm talking about myself, by the way. Commented Jan 23, 2020 at 18:00

This can also happen in magento2 if you have symlinked your module to the app/code/directory (or a template to app/design).

Magento2 by default won't follow symlinks for templates but if you enable template symlinks in the developer menu it will. However you still can't have template folders outside the magento directory. It will give this mildly cryptic error in this case.

The fix is to move the original folder you've symlinked to, inside the magento folder tree. Slightly strangely this restriction isn't applied to .php files so you can have a module "working" but with no templates.

You shouldn't allow symlinks on a production server but for development this can be very helpful.

This isn't what the questioner has done but the error given is the same.

  • After so many days of head-scratching this was the solution. The docs also fail to mention turning off secure keys in URL's otherwise you end up with an invalid session error in developer mode. Commented Dec 19, 2019 at 1:02
  • This was it for me! Now to so somehow gracefully alter registration.php depending on the staging environment..
    – MackieeE
    Commented Oct 12, 2022 at 15:31

Try in default.xml write:

<block class="MagicPack\magicheader\Block\magicheader" name="MagicPack_magicheader" template="MagicPack_magicheader::magicheader.phtml">
  • No joy, still getting the error: Invalid template file: 'MagicPack_magicheader::magicheader.phtml' in module: 'MagicPack_magicheader' block's name: 'MagicPack_magicheader' Any idea why? Thanks for the input. Commented Apr 22, 2016 at 18:37
  • Do you flush cache after changing content of XML files?
    – goral
    Commented Apr 23, 2016 at 16:30

Please use Capital letter for your module name you have used "magicheader" instead of that you should use "Magicheader" Change same everywhere.

  • OK, I've done this. Can I confirm the right naming convention? I will update the original post to match my changes. Thank you! Commented Apr 23, 2016 at 10:02
  • I have updated the module to being called Magicheader. I'm still sadly getting the same Invalid template file message. Any other ideas? Commented Apr 23, 2016 at 11:59

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