Twig\Error\LoaderError error in OpenCart occurs when the system cannot load the Twig template due to a missing file, invalid paths, or version incompatibility.
Major causes of the error
- Incorrect paths to Twig files in the code.
- Missing Twig template files
- Incompatibility of OpenCart and Twig versions. Especially after updating OpenCart to 3.0.3.6 and higher.
Solution for different OpenCart versions
OpenCart to 3.0.3.6
- Update the modifier cache and the template engine cache on the main admin page by clicking on the gear button.
- Editing the template loader: In the file
system/library/template/twig.phpreplace:
$loader = new \Twig_Loader_Array(array($filename . '.twig' => $code));
to
$loader1 = new \Twig_Loader_Array(array($filename . '.twig' => $code)); $loader2 = new \Twig_Loader_Filesystem(array(DIR_TEMPLATE)); // to find further includes $loader = new \Twig_Loader_Chain(array($loader1, $loader2));
OpenCart 3.0.3.6 and higher
$loader = new \Twig\Loader\ArrayLoader(array($filename . '.twig' => $code));
to
$loader1 = new \Twig\Loader\ArrayLoader(array($filename . '.twig' => $code)); $loader2 = new \Twig\Loader\FilesystemLoader(array(DIR_TEMPLATE)); // to find further includes $loader = new \Twig\Loader\ChainLoader(array($loader1, $loader2));
Following these recommendations will help prevent the error from occurring again and ensure stable operation of the store.
















































Comments