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


PHP Twig_Environment::createTemplate方法代码示例

本文整理汇总了PHP中Twig_Environment::createTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::createTemplate方法的具体用法?PHP Twig_Environment::createTemplate怎么用?PHP Twig_Environment::createTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twig_Environment的用法示例。


在下文中一共展示了Twig_Environment::createTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 /**
  * {@inheritdoc}
  */
 public function render(EmailInterface $email, array $data = array())
 {
     if (null !== $email->getTemplate()) {
         $data = $this->twig->mergeGlobals($data);
         /** @var \Twig_Template $template */
         $template = $this->twig->loadTemplate($email->getTemplate());
         if ($template->hasBlock('subject')) {
             $subject = $template->renderBlock('subject', $data);
         } else {
             $twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
             $subjectTemplate = $twig->createTemplate($email->getSubject());
             $subject = $subjectTemplate->render($data);
         }
         $body = $template->renderBlock('body', $data);
     } else {
         $twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
         $subjectTemplate = $twig->createTemplate($email->getSubject());
         $bodyTemplate = $twig->createTemplate($email->getContent());
         $subject = $subjectTemplate->render($data);
         $body = $bodyTemplate->render($data);
     }
     /** @var EmailRenderEvent $event */
     $event = $this->dispatcher->dispatch(SyliusMailerEvents::EMAIL_PRE_RENDER, new EmailRenderEvent(new RenderedEmail($subject, $body)));
     return $event->getRenderedEmail();
 }
开发者ID:JulienDemangeon,项目名称:SyliusMailerBundle,代码行数:28,代码来源:TwigAdapter.php

示例2: provideEmailWithoutTemplate

 /**
  * @param EmailInterface $email
  * @param array $data
  *
  * @return RenderedEmail
  */
 private function provideEmailWithoutTemplate(EmailInterface $email, array $data)
 {
     $twig = new \Twig_Environment(new \Twig_Loader_Array([]));
     $subjectTemplate = $twig->createTemplate($email->getSubject());
     $bodyTemplate = $twig->createTemplate($email->getContent());
     $subject = $subjectTemplate->render($data);
     $body = $bodyTemplate->render($data);
     return new RenderedEmail($subject, $body);
 }
开发者ID:sylius,项目名称:sylius,代码行数:15,代码来源:EmailTwigAdapter.php

示例3: __initialize

 /**
  * {@inheritdoc}
  */
 public function __initialize(array $params)
 {
     /* @var \Twig_Template[] $template */
     static $template = array();
     $params['safe'] = false;
     parent::__initialize($params);
     $function = $this->getParam('label_function');
     if (!isset($template[$function])) {
         $template[$function] = $this->twig->createTemplate(sprintf('{{ %s(status) }}', $function));
     }
     $this->callback = function ($value) use($template, $function) {
         return $template[$function]->render(array('status' => $value));
     };
 }
开发者ID:Codixis,项目名称:CSBill,代码行数:17,代码来源:StatusColumn.php

示例4: testPagerWithReset

 public function testPagerWithReset()
 {
     $this->pagerfantaExtension->expects($this->once())->method('renderPagerfanta')->with($this->identicalTo($pager = $this->createPagerfantaMock()), $this->identicalTo($name = 'name'), $this->identicalTo($options = ['routeParams' => ['foo' => 'bar']]))->will($this->returnValue($result = '<div>result</div>'));
     $options['routeParams']['grid']['baz'] = 'bat';
     $options['routeParams']['grid']['reset'] = true;
     $this->assertSame($result, $this->twig->createTemplate('{{ lug_grid_pager(pager, name, options) }}')->render(['pager' => $pager, 'name' => $name, 'options' => $options]));
 }
开发者ID:php-lug,项目名称:lug,代码行数:7,代码来源:GridExtensionTest.php

示例5: doStuff

 public function doStuff(\Twig_Environment $twig, $file, $showCode = false, $wrapInIframe = false)
 {
     $node = self::$nodeRouter->findByPath($file);
     if ($node) {
         return $twig->createTemplate(self::$renderer->render($node, $showCode, $wrapInIframe))->render([]);
     }
     return '';
 }
开发者ID:Inventis,项目名称:web-standards,代码行数:8,代码来源:FileInclude.php

示例6: getRenderedEmail

 /**
  * @param EmailInterface $email
  * @param array $data
  *
  * @return RenderedEmail
  */
 private function getRenderedEmail(EmailInterface $email, array $data)
 {
     if (null !== $email->getTemplate()) {
         $data = $this->twig->mergeGlobals($data);
         /** @var \Twig_Template $template */
         $template = $this->twig->loadTemplate($email->getTemplate());
         $subject = $template->renderBlock('subject', $data);
         $body = $template->renderBlock('body', $data);
         return new RenderedEmail($subject, $body);
     }
     $twig = new \Twig_Environment(new \Twig_Loader_Array([]));
     $subjectTemplate = $twig->createTemplate($email->getSubject());
     $bodyTemplate = $twig->createTemplate($email->getContent());
     $subject = $subjectTemplate->render($data);
     $body = $bodyTemplate->render($data);
     return new RenderedEmail($subject, $body);
 }
开发者ID:loic425,项目名称:Sylius,代码行数:23,代码来源:EmailTwigAdapter.php

示例7: renderPartial

 public function renderPartial(\Twig_Environment $twig, $title, $parameters = [])
 {
     $partial = $this->doctrine->getRepository('DataBundle:Partial')->findOneByTitle($title);
     if (!$partial || !$partial->getActive()) {
         return;
     }
     $tmpl = $twig->createTemplate($partial->getContent());
     return $tmpl->render($parameters);
 }
开发者ID:itaw,项目名称:cms,代码行数:9,代码来源:AppExtension.php

示例8: renderBlock

 /**
  * @param \Twig_Environment $twig
  * @param string $alias
  * @return \Twig_Template
  * @throws \InvalidArgumentException
  */
 public function renderBlock(\Twig_Environment $twig, $alias)
 {
     $block = $this->repo->createQueryBuilder('b')->where('b.alias = :alias')->setParameters(compact('alias'))->setMaxResults(1)->getQuery()->useResultCache(true)->setResultCacheId('cms_block.' . $alias)->getResult();
     $block = current($block);
     if (!$block) {
         throw new \InvalidArgumentException(sprintf("CMS block '%s' could not be found", $alias));
     }
     return $twig->createTemplate($block->getContent());
 }
开发者ID:vaidasif,项目名称:symfony-force,代码行数:15,代码来源:CMSBlockExtension.php

示例9: __initialize

 /**
  * {@inheritdoc}
  */
 public function __initialize(array $params)
 {
     /* @var \Twig_Template $template */
     static $template;
     $params['safe'] = false;
     parent::__initialize($params);
     $function = $this->getParam('label_function');
     if (!isset($template)) {
         $template = $this->twig->createTemplate(sprintf('<a href="{{ route }}">{{ client_name }}</a>', $function));
     }
     $this->callback = function ($clientName, Row $row, RouterInterface $router) use($template) {
         $clientId = $row->getField('client.id');
         if (!empty($clientId)) {
             $route = $router->generate('_clients_view', array('id' => $clientId));
             return $template->render(array('route' => $route, 'client_name' => $clientName));
         }
         return $clientName;
     };
 }
开发者ID:Codixis,项目名称:CSBill,代码行数:22,代码来源:ClientColumn.php

示例10: testEmbedFilter

 /**
  * @dataProvider getEmbedFilterData
  */
 public function testEmbedFilter($template, $calls = 1)
 {
     $twig = new \Twig_Environment(new \Twig_Loader_Array(array()), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
     $twig->addExtension(new CmfBlockExtension($this->getBlockHelper()));
     $this->getBlockHelper()->expects($this->exactly($calls))->method('embedBlocks');
     try {
         $twig->createTemplate($template)->render(array());
     } catch (\Twig_Error_Runtime $e) {
         throw $e->getPrevious();
     }
 }
开发者ID:symfony-cmf,项目名称:block-bundle,代码行数:14,代码来源:CmfBlockExtensionTest.php

示例11: templateFromString

 /**
  *
  * @param string $templateCode
  * @return \Twig_Template
  */
 public static function templateFromString($templateCode)
 {
     if (defined('TestMode')) {
         $options = array();
     } else {
         $options = array('cache' => APPPATH . 'cache');
     }
     $loader = new \Twig_Loader_Array(array());
     $twig = new \Twig_Environment($loader, $options);
     $template = $twig->createTemplate($templateCode);
     return $template;
 }
开发者ID:bbriggs,项目名称:web-languageforge,代码行数:17,代码来源:CommunicateHelper.php

示例12: renderTemplate

 /**
  * Render the template.
  *
  * @param string                        $template         The template string
  * @param LayoutInterface|MailInterface $templateInstance The template instance
  * @param array                         $variables        The variables of template
  *
  * @return string The rendered template
  *
  * @throws \Exception
  */
 protected function renderTemplate($template, $templateInstance, array $variables = array())
 {
     if (null !== $template) {
         if ($templateInstance instanceof TwigTemplateInterface) {
             $tpl = $this->renderer->loadTemplate($templateInstance->getFile());
             if ($tpl instanceof \Twig_Template) {
                 $template = $tpl->renderBlock($template, $variables);
                 $template = '' === $template ? null : $template;
             }
         } else {
             $tpl = $this->renderer->createTemplate($template);
             $template = $tpl->render($variables);
         }
     }
     return $template;
 }
开发者ID:sonatra,项目名称:SonatraMailerBundle,代码行数:27,代码来源:MailTemplater.php

示例13: renderContent

 /**
  * Renders content
  *
  * @param  Content $content
  * @return mixed
  */
 private function renderContent(Content $content)
 {
     $tpl = $content->has('template') ? " <comment>({$content->template})</comment>" : "";
     $this->app->writeln("Rendering: <info>{$content->target}</info>{$tpl}");
     // Only template files are run through Twig (template can be "none")
     if ($content->has('template')) {
         if ($content->paginate) {
             return $this->paginate($content);
         } else {
             $html = $this->twig->render($content->id, ['page' => $content, 'posts' => $this->getPosts($content), 'parent' => $this->getParent($content->parentId)]);
         }
     } else {
         $template = $this->twig->createTemplate($content->content);
         $html = $template->render([]);
     }
     // Save Content
     $this->savePage($content->target, $html);
 }
开发者ID:torann,项目名称:skosh-generator,代码行数:24,代码来源:Builder.php

示例14: index

 public function index(&$view, &$data, &$output)
 {
     if (!$this->config->get($this->config->get('config_theme') . '_status')) {
         exit('Error: A theme has not been assigned to this store!');
     }
     // This is only here for compatibility with older extensions
     if (substr($view, -3) == 'tpl') {
         $view = substr($view, 0, -3);
     }
     // If the default theme is selected we need to know which directory its pointing to
     if ($this->config->get('config_theme') == 'theme_default') {
         $theme = $this->config->get('theme_default_directory');
     } else {
         $theme = $this->config->get('config_theme');
     }
     // If there is a theme override we should get it
     $this->load->model('design/theme');
     $theme_info = $this->model_design_theme->getTheme($view, $theme);
     if ($theme_info) {
         // include and register Twig auto-loader
         include_once DIR_SYSTEM . 'library/template/Twig/Autoloader.php';
         Twig_Autoloader::register();
         // specify where to look for templates
         $loader = new \Twig_Loader_Filesystem(DIR_TEMPLATE);
         // initialize Twig environment
         $twig = new \Twig_Environment($loader, array('autoescape' => false));
         $template = $twig->createTemplate(html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8'));
         $output = $template->render($data);
     } else {
         if (is_file(DIR_TEMPLATE . $theme . '/template/' . $view . '.twig')) {
             $this->config->set('template_type', 'twig');
             $view = $theme . '/template/' . $view . '.twig';
         } elseif (is_file(DIR_TEMPLATE . 'default/template/' . $view . '.twig')) {
             $this->config->set('template_type', 'twig');
             $view = 'default/template/' . $view . '.twig';
         } elseif (is_file(DIR_TEMPLATE . $theme . '/template/' . $view . '.tpl')) {
             $this->config->set('template_type', 'php');
             $view = $theme . '/template/' . $view . '.tpl';
         } elseif (is_file(DIR_TEMPLATE . 'default/template/' . $view . '.tpl')) {
             $this->config->set('template_type', 'php');
             $view = 'default/template/' . $view . '.tpl';
         }
     }
 }
开发者ID:uksitebuilder,项目名称:opencart,代码行数:44,代码来源:theme.php

示例15: twig_template_from_string

/**
 * Loads a template from a string.
 *
 * <pre>
 * {{ include(template_from_string("Hello {{ name }}")) }}
 * </pre>
 *
 * @param Twig_Environment $env A Twig_Environment instance
 * @param string $template A template as a string
 *
 * @return Twig_Template A Twig_Template instance
 */
function twig_template_from_string(Twig_Environment $env, $template)
{
    return $env->createTemplate($template);
}
开发者ID:Jimm31,项目名称:Kassa,代码行数:16,代码来源:StringLoader.php


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