skip to Main Content

I have installed the Magento 2.0 platform on my localhost today. After completing all the setup and installation, when I tried to open the admin panel, it was showing a brown blank screen. When I switched to the developer mode, it is showing an invalid template error for require_js.phtml. The complete error is :

1 exception(s):
Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid template file: 'C:/xampp/htdocs/magento_demo/vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js'

Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid template file: 'C:/xampp/htdocs/magento_demo/vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js'
#0 C:xampphtdocsmagento_demovendormagentoframeworkViewElementTemplate.php(301): MagentoFrameworkViewElementTemplate->fetchView('C:/xampp/htdocs...')
#1 C:xampphtdocsmagento_demovendormagentoframeworkViewElementAbstractBlock.php(668): MagentoFrameworkViewElementTemplate->_toHtml()
#2 C:xampphtdocsmagento_demovendormagentoframeworkViewResultPage.php(249): MagentoFrameworkViewElementAbstractBlock->toHtml()
#3 C:xampphtdocsmagento_demovendormagentoframeworkViewResultLayout.php(171): MagentoFrameworkViewResultPage->render(Object(MagentoFrameworkAppResponseHttpInterceptor))
#4 C:xampphtdocsmagento_demogeneratedcodeMagentoBackendModelViewResultPageInterceptor.php(193): MagentoFrameworkViewResultLayout->renderResult(Object(MagentoFrameworkAppResponseHttpInterceptor))
#5 C:xampphtdocsmagento_demovendormagentoframeworkAppHttp.php(139): MagentoBackendModelViewResultPageInterceptor->renderResult(Object(MagentoFrameworkAppResponseHttpInterceptor))
#6 C:xampphtdocsmagento_demogeneratedcodeMagentoFrameworkAppHttpInterceptor.php(24): MagentoFrameworkAppHttp->launch()
#7 C:xampphtdocsmagento_demovendormagentoframeworkAppBootstrap.php(258): MagentoFrameworkAppHttpInterceptor->launch()
#8 C:xampphtdocsmagento_demoindex.php(39): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttpInterceptor))
#9 {main}

I have never used Magento before and have no idea what the issue is or how to solve it. Can anyone tell me what to do to solve the issue?

3

Answers


  1. You can execute composer update from project root it will update all missing dependencies.

    Other then this it you can flush Magento cache and re deploy static content, follow these steps:

    1) php bin/magento cache:flush or (sudo rm -rf <magento-root>/var/generated/* <magento-root>/pub/static/*)
    2) php bin/magento setup:static-content:deploy
    

    Now clean you browser cache and reload the page.

    Login or Signup to reply.
  2. Yes, This is the problem with windows. Windows uses "" as separator, the array "directories" contains entries with "/" as separator, so the check will always fail. So you need to fix this by replacing the separator in core file:

    MagentoFrameworkViewElementTemplateFileValidator
    

    function isPathInDirectories replace below code in isPathInDirectories function

    $realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));
    
    Login or Signup to reply.
  3. How to fix Invalid template file error in Magento2 after version upgrade?

    In case of windows, just replace this function isPathInDirectories in vendor/magento/framework/view/element/template/file/validator.php

    protected function isPathInDirectories($path, $directories)
    {
        $realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));
        if (!is_array($directories)) {
            $directories = (array)$directories;
        }
     
        foreach ($directories as $directory) {
            if (0 === strpos($realPath, $directory)) {
                return true;
            }
        }
        return false;
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search