Magento2 – Invalid template file issue

If you have installed a fresh copy of Magento2 or upgrading Magento2 from 2.2.5 to 2.2.6 or higher, you may see below issue:

1 exception(s):
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Magento_Backend::page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js'

Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Magento_Backend::page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js'
0 /vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView(false)
1 /vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml()
2 /vendor/magento/framework/View/Result/Page.php(248): Magento\Framework\View\Element\AbstractBlock->toHtml()
3 /vendor/magento/framework/View/Result/Layout.php(170): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
4 /vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
5 /vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
6 /vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
7 /generated/code/Magento/Framework/View/Result/Page/Interceptor.php(26): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
8 /vendor/magento/framework/App/Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
9 /vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http->launch()
10/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))

You might already have tried below solutions:

If the above did not work for you, try below:

Go to Magento Admin backend -> Content -> Design -> Configuration and check the theme:

Design Configuration page

If you do not see any theme assigned, then go ahead and edit the website configuration, assign a theme, clear the cache and try again.

I spent days installing and reinstalling different versions of Magento 2 and applying the solutions, but those did not work. Apparently, one of the modules was trying to refer to the theme and since it did not find any, the Invalid template file error was being thrown.

If you do not have developer mode enabled, then you will most likely see blank page since the exception would not show up on the home page. In that case, enable developer mode if you are making changes.

Other questions this post might help

  • “Invalid template file” error in Magento 2 with a custom module
  • Magento 2 invalid template exception just after installation
  • Blank admin page on Magento 2.3.0 CE in localhost
  • magento 2 simple block firing exception Invalid template file

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.