本文整理汇总了PHP中Twig_Environment::resolveTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::resolveTemplate方法的具体用法?PHP Twig_Environment::resolveTemplate怎么用?PHP Twig_Environment::resolveTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Environment
的用法示例。
在下文中一共展示了Twig_Environment::resolveTemplate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render($v, $data)
{
$view = str_replace('{module}', $this->app['Module'], $v);
if (!$this->twig->resolveTemplate($view)) {
$view = str_replace('@{module}/', '', $v);
}
$data = array_merge($data, ["logged" => $this->app['auth']->isLogged(), "User" => $this->app['auth']->getUser(), "module" => $this->app['Module']]);
foreach ($this->app->keys() as $key) {
$data[$key] = $this->app[$key];
}
return $this->twig->render($view, $data);
}
示例2: loadTemplate
/**
* Loads the template.
*
* @param string $template The template relative path
* @param array $vars The template variables
*
* @throws TemplateNotFoundException When template does not exist
* @throws UnsupportedTemplateException When template format is not supported
*
* @return TemplateInterface
*/
public function loadTemplate($template, array $vars = [])
{
if (!$this->supports($template)) {
throw new UnsupportedTemplateException(sprintf('Template %s is not supported by this engine.', $template));
}
try {
$reference = $this->twig->resolveTemplate($template);
} catch (\Twig_Error_Loader $exception) {
throw new TemplateNotFoundException(sprintf('Template %s does not exist.', $template), $exception);
} catch (\Exception $exception) {
throw new UnsupportedTemplateException(sprintf('Invalid template %s provided.', $template), $exception);
}
return new Template($reference->getTemplateName(), $this->twig->mergeGlobals($vars));
}
示例3: render
public function render(Environment $twig)
{
$templates = ArrayCollection::create($this->template)->map(function ($template) {
return Str::endsWith($template, '.twig') ? $template : $template . '.twig';
});
$this->setContent($twig->resolveTemplate($templates->toArray())->render($this->variables->toArray()));
$this->rendered = true;
}
示例4: view
public function view(\Twig_Environment $env, $path, $variables = array())
{
$name = preg_replace("/\\.[^.\\s]{3,4}\$/", "", $path);
// Remove ext.
$name = str_replace('/', '_', $name);
$html = $env->resolveTemplate($path)->render($variables);
$html = "<script type=\"text/html\" id=\"view_{$name}\">{$html}</script>";
return $html;
}
示例5: resolveTemplate
/**
* Add a new namespace to the loader.
*
* @param \TwigBridge\StringView\StringView $view
* @return \TwigBridge\Twig\Template
*/
public function resolveTemplate(StringView $view)
{
$currentLoader = $this->twig->getLoader();
$loader = new Loader($view);
$this->twig->setLoader($loader);
$template = $this->twig->resolveTemplate($view->getName());
$this->twig->setLoader($currentLoader);
return $template;
}
示例6: render
private function render(\Twig_Environment $env, $context, TwigInjectEvent $event)
{
$content = '';
if (sizeof($injections = $event->getInjections())) {
foreach ($injections as $item) {
if ($item instanceof TwigInjectInclude) {
$content .= $env->resolveTemplate($item->getTemplate())->render(array_merge($context, $item->getParameters()));
continue;
}
if ($item instanceof TwigInjectRender) {
$content .= $this->fragment->render(new ControllerReference($item->getController(), $item->getAttributes(), $item->getQuery()), $item->getStrategy());
continue;
}
}
}
return $content;
}
示例7: render
/**
* @param \Twig_Environment $env
* @param $context
* @param TwigTemplateEvent $event
*
* @return string
*/
protected function render(\Twig_Environment $env, $context, TwigTemplateEvent $event)
{
$codes = $event->getCodes();
$compiled = '';
if (count($codes)) {
foreach ($codes as $code) {
if ($code instanceof TwigEventInclude) {
$compiled .= $env->resolveTemplate($code->getTemplate())->render(array_replace_recursive($context, $code->getParameters()));
continue;
}
if ($code instanceof TwigEventString) {
$compiled .= $env->render($code->getTemplateString(), array_replace_recursive($context, $code->getParameters()));
continue;
}
if ($code instanceof TwigEventRender) {
$reference = new ControllerReference($code->getController(), $code->getAttributes(), $code->getQuery());
$compiled .= $this->fragment->render($reference, $code->getStrategy());
continue;
}
}
}
return $compiled;
}
示例8: twig_include
/**
* Renders a template.
*
* @param Twig_Environment $env
* @param array $context
* @param string|array $template The template to render or an array of templates to try consecutively
* @param array $variables The variables to pass to the template
* @param bool $withContext
* @param bool $ignoreMissing Whether to ignore missing templates or not
* @param bool $sandboxed Whether to sandbox the template or not
*
* @return string The rendered template
*/
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();
}
}
try {
return $env->resolveTemplate($template)->render($variables);
} catch (Twig_Error_Loader $e) {
if (!$ignoreMissing) {
throw $e;
}
}
if ($isSandboxed && !$alreadySandboxed) {
$sandbox->disableSandbox();
}
}
示例9: showSourceCode
public function showSourceCode(\Twig_Environment $twig, $template)
{
return $twig->render('@CodeExplorer/source_code.html.twig', ['controller' => $this->getController(), 'template' => $this->getTemplateSource($twig->resolveTemplate($template))]);
}