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;
 }
 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();
 }
Exemple #3
1
 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);
 }
 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);
     });
 }
 /**
  * {@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();
 }
 /**
  * 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([]);
         }
     }
 }
 /**
  * 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');
 }
 function it_prepares_email_properly($mailer, $twigEnvironment, \Twig_Template $template)
 {
     $from = '*****@*****.**';
     $to = '*****@*****.**';
     $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);
 }
 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];
 }
 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'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("::base_articles.html.twig", "CestomArticleBundle:Pays:index.html.twig", 1);
     $this->blocks = array('body' => array($this, 'block_body'));
 }
 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'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("base.html", "index.html", 1);
     $this->blocks = array('header' => array($this, 'block_header'), 'content' => array($this, 'block_content'), 'footer' => array($this, 'block_footer'), 'bottomscript' => array($this, 'block_bottomscript'));
 }
 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'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("block.html.twig", "core/themes/bartik/templates/block--system-branding-block.html.twig", 1);
     $this->blocks = array('content' => array($this, 'block_content'));
 }
 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'));
 }
 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'));
 }
 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();
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("@block/block.html.twig", "core/themes/seven/templates/block--local-actions-block.html.twig", 1);
     $this->blocks = array('content' => array($this, 'block_content'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("base.html.twig", "home.html.twig", 1);
     $this->blocks = array('title' => array($this, 'block_title'), 'body' => array($this, 'block_body'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("base.html.twig", "childrenofotoeos/edit.html.twig", 1);
     $this->blocks = array('body' => array($this, 'block_body'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("block--bare.html.twig", "themes/bootstrap/templates/block--page-title-block.html.twig", 1);
     $this->blocks = array();
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("base.html.twig", "blog/index.html.twig", 1);
     $this->blocks = array('body_id' => array($this, 'block_body_id'), 'main' => array($this, 'block_main'), 'sidebar' => array($this, 'block_sidebar'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("layout.html", "help.html", 1);
     $this->blocks = array('body' => array($this, 'block_body'), 'scripts' => array($this, 'block_scripts'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("TwigBundle::layout.html.twig", "TwigBundle:Exception:exception_full.html.twig", 1);
     $this->blocks = array('head' => array($this, 'block_head'), 'title' => array($this, 'block_title'), 'body' => array($this, 'block_body'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("CivixFrontBundle:News:index.html.twig", "CivixFrontBundle:Group/News:index.html.twig", 1);
     $this->blocks = array();
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("FSPBundle:User:accueil.html.twig", "FSPBundle:Theme:cours.html.twig", 1);
     $this->blocks = array('blocCentre' => array($this, 'block_blocCentre'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 3
     $this->parent = $this->loadTemplate("::admin.html.twig", "AdminBundle:Enseignant:edit.html.twig", 3);
     $this->blocks = array('body' => array($this, 'block_body'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("@WebProfiler/Profiler/layout.html.twig", "@Security/Collector/security.html.twig", 1);
     $this->blocks = array('toolbar' => array($this, 'block_toolbar'), 'menu' => array($this, 'block_menu'), 'panel' => array($this, 'block_panel'));
 }
 public function __construct(Twig_Environment $env)
 {
     parent::__construct($env);
     // line 1
     $this->parent = $this->loadTemplate("SensioDistributionBundle::Configurator/layout.html.twig", "SensioDistributionBundle:Configurator/Step:doctrine.html.twig", 1);
     $this->blocks = array('title' => array($this, 'block_title'), 'content' => array($this, 'block_content'));
 }