当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Environment::resolveTemplate方法代码示例

本文整理汇总了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);
 }
开发者ID:frnks,项目名称:meister,代码行数:12,代码来源:Twig.php

示例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));
 }
开发者ID:Symfomany,项目名称:laravelcinema,代码行数:25,代码来源:TwigEngineAdapter.php

示例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;
 }
开发者ID:gmo,项目名称:common,代码行数:8,代码来源:TwigResponse.php

示例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;
 }
开发者ID:elfchat,项目名称:elfchat,代码行数:9,代码来源:ElfChatExtension.php

示例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;
 }
开发者ID:diyphpdeveloper,项目名称:twigbridge,代码行数:15,代码来源:Factory.php

示例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;
 }
开发者ID:intaro,项目名称:twig-injection-bundle,代码行数:17,代码来源:InjectionExtension.php

示例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;
 }
开发者ID:shapecode,项目名称:twig-template-event-bundle,代码行数:30,代码来源:EventExtension.php

示例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();
    }
}
开发者ID:stler,项目名称:NMFrame,代码行数:37,代码来源:Core.php

示例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))]);
 }
开发者ID:rasanga,项目名称:symfony-demo,代码行数:4,代码来源:SourceCodeExtension.php


注:本文中的Twig_Environment::resolveTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。