You are here

function twig_include in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/twig/twig/lib/Twig/Extension/Core.php \twig_include()

Renders a template.

Parameters

Twig_Environment $env:

array $context:

string|array $template The template to render or an array of templates to try consecutively:

array $variables The variables to pass to the template:

bool $withContext:

bool $ignoreMissing Whether to ignore missing templates or not:

bool $sandboxed Whether to sandbox the template or not:

Return value

string The rendered template

1 string reference to 'twig_include'
Twig_Extension_Core::getFunctions in vendor/twig/twig/lib/Twig/Extension/Core.php

File

vendor/twig/twig/lib/Twig/Extension/Core.php, line 1442

Code

function twig_include(Twig_Environment $env, $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false) {
  $alreadySandboxed = false;
  $sandbox = null;
  if ($withContext) {
    $variables = array_merge($context, $variables);
  }
  if ($isSandboxed = $sandboxed && $env
    ->hasExtension('sandbox')) {
    $sandbox = $env
      ->getExtension('sandbox');
    if (!($alreadySandboxed = $sandbox
      ->isSandboxed())) {
      $sandbox
        ->enableSandbox();
    }
  }
  $result = null;
  try {
    $result = $env
      ->resolveTemplate($template)
      ->render($variables);
  } catch (Twig_Error_Loader $e) {
    if (!$ignoreMissing) {
      if ($isSandboxed && !$alreadySandboxed) {
        $sandbox
          ->disableSandbox();
      }
      throw $e;
    }
  }
  if ($isSandboxed && !$alreadySandboxed) {
    $sandbox
      ->disableSandbox();
  }
  return $result;
}