"Invalid template file" error in Magento 2 with a custom module

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

app\code\MagicPack\Magicheader\View\frontend\templates\magicheader.phtml

This needed to be:

app\code\MagicPack\Magicheader\view\frontend\templates\magicheader.phtml

With a small case "v".

Hope that helps someone in the future.


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.