本文整理汇总了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();
}
示例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);
}
示例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));
};
}
示例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]));
}
示例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 '';
}
示例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);
}
示例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);
}
示例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());
}
示例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;
};
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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';
}
}
}
示例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);
}