-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Twig cache file has path instead of name in laravel view cache for getTemplateName() #438
Comments
I think the issue might be that the load method here: https://github.com/rcrowe/TwigBridge/blob/master/src/Engine/Compiler.php is sending in the path to public function load($path)
{
// Load template
try {
$tmplWrapper = $this->twig->load($path);
} catch (Exception $e) {
throw new InvalidArgumentException("Error loading $path: ". $e->getMessage(), $e->getCode(), $e);
}
return $tmplWrapper;
} If we check the load method in twig, it takes in a name: https://github.com/twigphp/Twig/blob/3.x/src/Environment.php public function load($name): TemplateWrapper
{
if ($name instanceof TemplateWrapper) {
return $name;
}
return new TemplateWrapper($this, $this->loadTemplate($this->getTemplateClass($name), $name));
} Should we normalize the path before sending it to twig? Something like this maybe: public function load($path)
{
// Load template
try {
$path = str_replace(resource_path('views') . '/', '', $path);
if (substr($path, -5) === ".twig") {
$path = substr($path, 0, -5);
}
$path = ViewName::normalize($path);
$tmplWrapper = $this->twig->load($path);
} catch (Exception $e) {
throw new InvalidArgumentException("Error loading $path: ". $e->getMessage(), $e->getCode(), $e);
}
return $tmplWrapper;
} |
Found this PR and my issue sounds similar to what is mentioned in this: #424 |
@barryvdh I've created a PR for this fix: #439 I'm not sure if this is the proper solution for this so please suggest any updates or alternative approaches if required. Thanks! Update: Closed the PR as it will not work in all the cases, for example with themes. Could this potentially be a problem with my config? Any help on this is appreciated. Thanks! |
Hi,
I have a laravel app using twigbridge. Whenever a template is rendered for the first time, its view cache file contains its directory path instead of its name in
getTemplateName()
method. All the sub templates rendered by that template (usinginclude
) have correct names in their view cache files. This is causing problems with laravel view composer as it is not being triggered due to the wrong template names.For example, the cache file has:
instead of:
Is this expected behaviour? Is there a way to use template names instead of path in this case?
Thanks!
The text was updated successfully, but these errors were encountered: