Magento2提示错误 Invalid template file解决方法
在windows上安装Magento2.3.5时报错:
1 exception(s): Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'app/design/frontend/Mgs/hebes/Magento_Theme/templates/page/js/require_js.phtml' in module: '' block's name: 'require.js'
这是因为查找模板文件的时候,windows的分隔符和Linux分隔符不同导致。
解决如下:
打开vendor\magento\framework\View\Element\Template\File\Validator.php,在isPathInDirectories方法中添加代码:
protected function isPathInDirectories($path, $directories)
{
if (!is_array($directories)) {
$directories = (array)$directories;
}
$realPath = $this->fileDriver->getRealPath($path);
$realPath = str_replace('\\', '/', $realPath); // 添加在这里
foreach ($directories as $directory) {
if (0 === strpos($realPath, $directory)) {
return true;
}
}
return false;
}
问题解决.