本文整理汇总了PHP中Twig_Template类的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Template类的具体用法?PHP Twig_Template怎么用?PHP Twig_Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Twig_Template类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderBlock
public function renderBlock(\Twig_Template $template, ColumnInterface $column, $object, $context, $blocks)
{
try {
$value = $this->accessor->getValue($object, $column->getName());
} catch (ExceptionInterface $exception) {
$value = null;
}
$block = 'crudify_field_' . $column->getType();
// check if the block exists
$hasBlock = false;
if (!isset($blocks[$block])) {
$current = $template;
do {
if ($current->hasBlock($block)) {
break;
}
$current = $current->getParent($context);
} while ($current instanceof \Twig_Template);
if ($current instanceof \Twig_Template) {
$hasBlock = true;
}
} else {
$hasBlock = true;
}
if ($hasBlock) {
$context['value'] = $value;
$context['definition'] = $column->getParent()->getParent();
$context['column'] = $column;
$context['object'] = $object;
$result = $template->renderBlock($block, $context, $blocks);
} else {
$result = htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
}
return $result;
}
示例2: findAllBlocks
public function findAllBlocks(\Twig_Template $template, array $context)
{
if (false !== ($parent = $template->getParent($context))) {
return array_unique(array_merge($this->findAllBlocks($parent, $context), $template->getBlockNames()));
}
return $template->getBlockNames();
}
示例3: renderTwigBlock
protected function renderTwigBlock(\Twig_Template $template, $blockName, $context = array())
{
foreach ($template->getEnvironment()->getGlobals() as $key => $value) {
if (!array_key_exists($key, $context)) {
$context[$key] = $value;
}
}
return $template->renderBlock($blockName, $context);
}
示例4: set_lazy_block
public function set_lazy_block(array &$context, \Twig_Template $tpl, $name, $key)
{
if (empty($key) || !is_string($key)) {
throw new \Exception(sprintf("key(%s) must be string", json_encode($key)));
}
\Dev::shareCacheValue($key, function ($app) use(&$context, &$tpl, $name) {
$tpl->displayBlock($name, $context);
});
}
示例5: populateMessage
/**
* Fills in message using blocks from a template (`body`, `subject`, `from`).
* If there is no `body` block then whole template will be used.
* If there is no `subject` or `from` block then corresponding default value will be used.
* @param \Swift_Message $message
* @param \Twig_Template $templateContent
* @param array $data
*/
protected function populateMessage(\Swift_Message $message, \Twig_Template $templateContent, $data)
{
$body = $templateContent->hasBlock('body') ? $templateContent->renderBlock('body', $data) : $templateContent->render($data);
$subject = $templateContent->hasBlock('subject') ? $templateContent->renderBlock('subject', $data) : $this->defaultSubject;
$from = $templateContent->hasBlock('from') ? $templateContent->renderBlock('from', $data) : $this->defaultFrom;
$message->setFrom($from)->setSubject($subject)->setBody($body, 'text/html', 'utf-8');
}
示例6: it_prepares_email_properly
function it_prepares_email_properly($mailer, $twigEnvironment, \Twig_Template $template)
{
$from = 'test-email@sylius.org';
$to = 'test-recipient@sylius.org';
$templateName = 'test-template';
$context = array('dummy', 'context');
$template->renderBlock('subject', $context)->shouldBeCalled();
$template->renderBlock('body_text', $context)->shouldBeCalled();
$template->renderBlock('body_html', $context)->shouldBeCalled();
$twigEnvironment->mergeGlobals($context)->shouldBeCalled()->willReturn($context);
$twigEnvironment->loadTemplate($templateName)->willReturn($template);
$mailer->send(Argument::any())->shouldBeCalled();
$this->sendEmail($templateName, $context, $from, $to);
}
示例7: getTemplateSource
private function getTemplateSource(\Twig_Template $template)
{
// Twig templates are not always stored in files, and so there is no
// API to get the filename from a template name in a generic way.
// The logic used here works only for templates stored in app/Resources/views
// and referenced via the "filename.html.twig" notation, not via the "::filename.html.twig"
// one or stored in bundles. This is enough for the needs of the demo app.
$filePath = $this->kernelRootDir . '/Resources/views/' . $template->getTemplateName();
$sourceCode = $template->getSource();
// Temporary workaround for https://github.com/twigphp/Twig/issues/2011
if (null === $sourceCode) {
$sourceCode = @file_get_contents($filePath);
}
return ['file_path' => $filePath, 'starting_line' => 1, 'source_code' => $sourceCode];
}
示例8: renderBlock
/**
* {@inheritdoc}
*/
public function renderBlock(FormView $view, $resource, $blockName, array $variables = array())
{
$cacheKey = $view->vars[self::CACHE_KEY_VAR];
$context = $this->environment->mergeGlobals($variables);
ob_start();
// By contract,This method can only be called after getting the resource
// (which is passed to the method). Getting a resource for the first time
// (with an empty cache) is guaranteed to invoke loadResourcesFromTheme(),
// where the property $template is initialized.
// We do not call renderBlock here to avoid too many nested level calls
// (XDebug limits the level to 100 by default)
$this->template->displayBlock($blockName, $context, $this->resources[$cacheKey]);
return ob_get_clean();
}
示例9: render
/**
* Render the current request action
*/
public function render()
{
if (isset($this->controllerTemplate)) {
if (isset($this->actionTemplate)) {
return $this->controllerTemplate->render(['actionTemplate' => $this->actionTemplate->render([])]);
} else {
return $this->controllerTemplate->render([]);
}
} else {
if (isset($this->actionTemplate)) {
return $this->actionTemplate->render([]);
}
}
}
示例10: __construct
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
// line 1
$this->parent = $this->loadTemplate("FOSUserBundle::layout.html.twig", "FOSUserBundle:Security:login.html.twig", 1);
$this->blocks = array('fos_user_content' => array($this, 'block_fos_user_content'));
}
开发者ID:JerryAimee,项目名称:symfony.github.io,代码行数:7,代码来源:c2f2214180f3ea8f45dab864794418ede5bab27483d7a16ed2be1468711eed93.php
示例11: __construct
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
// line 1
$this->parent = $this->loadTemplate("@WebProfiler/Profiler/layout.html.twig", "WebProfilerBundle:Collector:translation.html.twig", 1);
$this->blocks = array('toolbar' => array($this, 'block_toolbar'), 'menu' => array($this, 'block_menu'), 'panel' => array($this, 'block_panel'), 'panelContent' => array($this, 'block_panelContent'));
}
开发者ID:tsurune,项目名称:Pruebas,代码行数:7,代码来源:29fc25868eeeb7615ab16174079dd604d6d2cf9942d01cc4f7dc3119d9661129.php
示例12: __construct
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
// line 1
$this->parent = $this->loadTemplate("::base.html.twig", "LaisoArmBundle:Bloc:index.html.twig", 1);
$this->blocks = array('title' => array($this, 'block_title'), 'breadcumbs' => array($this, 'block_breadcumbs'), 'body' => array($this, 'block_body'));
}
开发者ID:gasikely2,项目名称:sgpec,代码行数:7,代码来源:dce453cf93c0612fd2263bd4f5d0838f66516d896c87c978f1bbfdbbc4efe979.php
示例13: __construct
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
// line 1
$this->parent = $this->loadTemplate("knp_menu_base.html.twig", "knp_menu.html.twig", 1);
$this->blocks = array('compressed_root' => array($this, 'block_compressed_root'), 'root' => array($this, 'block_root'), 'list' => array($this, 'block_list'), 'children' => array($this, 'block_children'), 'item' => array($this, 'block_item'), 'linkElement' => array($this, 'block_linkElement'), 'spanElement' => array($this, 'block_spanElement'), 'label' => array($this, 'block_label'));
}
开发者ID:KaanTolunayKilic,项目名称:miniBlog,代码行数:7,代码来源:ad7b17b6b800ad1b773e111b2b41da06c72db56ce0b0dc892d35079027b60dff.php
示例14: __construct
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
// line 1
$this->parent = $this->loadTemplate("AnnuaireBundle:Default:index.html.twig", "AnnuaireBundle:Template:enregistrer.html.twig", 1);
$this->blocks = array('lienretour' => array($this, 'block_lienretour'), 'container' => array($this, 'block_container'));
}
开发者ID:mkemiche,项目名称:Annuaire,代码行数:7,代码来源:83aa5c9dae6f431f92b4ac1e1d8e3b3aa92e60beb2f8f23288f1e4ea30269d88.php
示例15: __construct
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
// line 1
$this->parent = $this->loadTemplate("@block/block.html.twig", "block.html.twig", 1);
$this->blocks = array();
}
开发者ID:m-ark22,项目名称:bdlp,代码行数:7,代码来源:98d1d5296cbff6583eb9aed6f54391eae18b996444eeb586167dfe3955b08186.php