You are here

public function Twig_Environment::resolveTemplate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Environment.php \Twig_Environment::resolveTemplate()

Tries to load a template consecutively from an array.

Similar to loadTemplate() but it also accepts Twig_TemplateInterface instances and an array of templates where each is tried to be loaded.

Parameters

string|Twig_Template|array $names A template or an array of templates to try consecutively:

Return value

Twig_Template

Throws

Twig_Error_Loader When none of the templates can be found

Twig_Error_Syntax When an error occurred during compilation

File

vendor/twig/twig/lib/Twig/Environment.php, line 487

Class

Twig_Environment
Stores the Twig configuration.

Code

public function resolveTemplate($names) {
  if (!is_array($names)) {
    $names = array(
      $names,
    );
  }
  foreach ($names as $name) {
    if ($name instanceof Twig_Template) {
      return $name;
    }
    try {
      return $this
        ->loadTemplate($name);
    } catch (Twig_Error_Loader $e) {
    }
  }
  if (1 === count($names)) {
    throw $e;
  }
  throw new Twig_Error_Loader(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names)));
}