function Environment::resolveTemplate
Tries to load a template consecutively from an array.
Similar to load() but it also accepts instances of \Twig\TemplateWrapper and an array of templates where each is tried to be loaded.
Parameters
string|TemplateWrapper|array<string|TemplateWrapper> $names A template or an array of templates to try consecutively:
Throws
LoaderError When none of the templates can be found
SyntaxError When an error occurred during compilation
File
-
vendor/
twig/ twig/ src/ Environment.php, line 479
Class
- Environment
- Stores the Twig configuration and renders templates.
Namespace
TwigCode
public function resolveTemplate($names) : TemplateWrapper {
if (!\is_array($names)) {
return $this->load($names);
}
$count = \count($names);
foreach ($names as $name) {
if ($name instanceof Template) {
trigger_deprecation('twig/twig', '3.9', 'Passing a "%s" instance to "%s" is deprecated.', Template::class, __METHOD__);
return new TemplateWrapper($this, $name);
}
if ($name instanceof TemplateWrapper) {
return $name;
}
if (1 !== $count && !$this->getLoader()
->exists($name)) {
continue;
}
return $this->load($name);
}
throw new LoaderError(\sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names)));
}