Closed mrardon closed 13 years ago
Issue might be in parser/classes/view/twig.php.
The method parser(), responsible for creating a parser object, stores the created object in a static variable so it can be reused later. Because of that, the newly created parser_loader object is not used in the twig environment on subsequent calls, leading to this error.
To verify this, comment line 58 in that file (where the static is returned so it will create a new environment every time you call the parser, and see if that fixes the problem.
Correction, change it so it reads
if ( ! empty(static::$_parser))
{
static::$_parser->setLoader(static::$_parser_loader);
return static::$_parser;
}
This will update the loader of the current Twig object.
That definitely fixed it! Great work!
Issue:
When I change paths (i.e. views/contacts to views/layouts) Twig throws an error)
Think it has something to do with Twig holding on to the paths from a previous instance. (I dunno if its a problem with Parser or Twig as a quick glance of each's internals revealed nothing to me.)
To recreate:
Call
$data["content"] = render('contacts/show.twig', $data);
Then call$layout = View::factory('layouts/application.twig', $data, false);
Views Folder Structure:
Error w/ Backtrace:
APPPATH actually showed my path in the error - I just removed it
Something I tried
I var_dumped the $_parser_loader when the exception was caught (Around line 48 in parser/classes/view/twig.php) and got this
This leads me to believe that something "statically" being set is not in fact changing on the Twig side of things as the var_dump reveals the paths were set correctly in the Twig_Loader_Filesystem and in the Error w/Backtrace shows that the paths are different (i.e.
APPPATH/views/layouts, APPPATH/views
vs.APPPATH/views/contacts, APPPATH/views
)Let me know if you need other details, I tried to be as thorough as possible. Thanks, Matt