1

I'm new to Magento and when first installed on my localhost there was no errors, but yesterday setting up second project of Magento on my localhost the following errors appeared:

[2019-12-20 13:17:30] main.CRITICAL: Invalid template file: 'F:/xampp/htdocs/magento2/vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js' [] []

[2019-12-20 13:17:30] main.CRITICAL: Invalid template file: 'F:/xampp/htdocs/magento2/vendor/magento/module-ui/view/base/templates/wysiwyg/active_editor.phtml' in module: 'Magento_Ui' block's name: 'theme.active.editor' [] []

Please help that how can I resolved it?

3
  • deploy theme , it required Dec 20, 2019 at 13:48
  • another install on windows working ok? (well your first one) I had nothing but pain doing installing on windows.
    – Barry
    Dec 20, 2019 at 14:50
  • yes, the first installation is working good. But second one it's not working. showing the same error as above
    – Rakhi
    Dec 23, 2019 at 4:54

2 Answers 2

2

I got the Solution as below,

foreach ($directories as $directory) {
    if (0 === strpos($realPath, $directory)) {
        return true;
    }
}

Currently we can go for a dirty quick change in the above foreach loop so that we can run our magento with no further problems on this:

#/vendor/magento/framework/View/Element/Template/File/Validator.php:139
foreach ($directories as $directory) {
    // Add this line
    $realDirectory = $this->fileDriver->getRealPath($directory);
    // and replace `$directory` with `$realDirectory`
    if (0 === strpos($realPath, $realDirectory)) {
        return true;
    }
}
1
  • After this change is done. Once again clear Magento cache and restart the apache server.
    – Rakhi
    Dec 23, 2019 at 6:41
1

Firstly I think it is important to explain the reason why the error is occuring... The error is occurring because of the backward slashes on the path that should be replaced with a forward slash in Windows. The more "cleaner" alternative (that I prefer) is to not touch the foreach loop and instead add this line of code immediately above the loop:

$realPath = str_replace('\\', '/', $realPath); this line of code is declarative and hence more readable, it's purpose can be understood at first glance. it serves to replace the backward slashes on the path with a forward slash...the function would then be as follows:

protected function isPathInDirectories($path, $directories)
{
    if (!is_array($directories)) {
        $directories = (array)$directories;
    }
    $realPath = $this->fileDriver->getRealPath($path);
    $realPath = str_replace('\\', '/', $realPath); // the line we added
    foreach ($directories as $directory) {
        if (0 === strpos($realPath, $directory)) {
            return true;
        }
    }
    return false;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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