pleasedisturb pleasedisturb - 1 year ago 112
Twig Question

How do I get meaningful error message with Twig?

I'm using Twig without Symphony. It is installed via composer and used with composers autoloader. In bootstrap phase Twig is instantiated as:

// lib_get_basedir returns root directory of library.
$templatePath = sprintf("%s/data/templates", lib_get_basedir());
// $conf stores configuration values.
// tmp_dir is library directory for temporary files.
$cachePath = sprintf("%s/twig_cache", $conf->get("tmp_dir"));
$loader = new \Twig_Loader_Filesystem($templatePath);
$twig = new \Twig_Environment($loader, [
"cache" => $cachePath
$gettextFun = new \Twig_SimpleFunction("gettext", function ($value) {
return gettext($value);
$twig->getExtension("core")->setNumberFormat(2, ",", ".");
$twig->addExtension(new \Twig_Extensions_Extension_I18n());
$twig->addExtension(new \Twig_Extensions_Extension_Intl());
$twig->addExtension(new \Twig_Extensions_Extension_Text());

When I try to render a template using this Twig_Environment instance, I only get this meaningless error:

Error 2: include_once(/var/lib/wlc/tmp/twig_cache/16/167b8e710323d3fc9a90a6d582652a570b1993e4d46cebd1350484a0c3ad445e.php): failed to open stream: No such file or directory
File: phar:///usr/local/share/wlc/libwlc-local-1.2.phar/vendor/twig/twig/lib/Twig/Cache/Filesystem.php
Line: 49

I already checked permissions on the
folder and its parents and that should not be the problem. This error now also happens on machines where there is only one user who runs php-fcgi and owns the cache directory.

This error doesn't happen if I pass

My question is, how can I debug this issue?

Answer Source

I faced same problem with Twig v1.24.1 in slim twig-view.

What version do you use?

I found this commit.

but this commit isn't included master branch now.

I solved with updating twig version in my composer.json as follows,

"twig/twig": "1.x-dev"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download