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


PHP Twig_Template::renderBlock方法代码示例

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


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

示例1: 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');
 }
开发者ID:syzygymsu,项目名称:syzygy-framework-bundle,代码行数:15,代码来源:Composer.php

示例2: array

 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);
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:14,代码来源:TwigSwiftMailerSpec.php

示例3: 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;
 }
开发者ID:bravesheep,项目名称:crudify-bundle,代码行数:35,代码来源:CrudifyExtension.php

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

示例5: renderBlock

 /**
  * Render block.
  *
  * @param \Twig_Environment $twig
  * @param                   $name
  * @param                   $parameters
  *
  * @return string
  */
 private function renderBlock(\Twig_Environment $twig, $name, $parameters)
 {
     // load template if needed
     if (is_null($this->template)) {
         // get template name
         if (is_null($this->theme)) {
             $this->theme = 'PlatinumPixsSimplePaginationBundle::blocks.html.twig';
         }
         $this->template = $twig->loadTemplate($this->theme);
     }
     if ($this->template->hasBlock($name)) {
         return $this->template->renderBlock($name, $parameters);
     } else {
         throw new \InvalidArgumentException(sprintf('Block "%s" doesn\'t exist in template "%s".', $name, $this->theme));
     }
 }
开发者ID:platinumpixs,项目名称:symfony2-simple-pagination,代码行数:25,代码来源:TwigExtension.php

示例6: renderBlock

 public function renderBlock(\Twig_Environment $env, $themeRoot, $name, array $variables)
 {
     if (!$this->template) {
         $this->template = $env->loadTemplate(reset($this->resources));
     }
     $blocks = $this->getBlocks($env, $themeRoot);
     return $this->template->renderBlock($name, $variables, $blocks);
 }
开发者ID:webfactory,项目名称:navigation-bundle,代码行数:8,代码来源:NavigationThemeExtension.php

示例7: renderCell

 /**
  * Renders a cell
  *
  * @param Cell $cell
  *
  * @return string
  */
 public function renderCell(Cell $cell)
 {
     $block = $cell->vars['type'] . '_cell';
     /*if(!$this->template->hasBlock($block)) {
           $block = 'text_cell';
       }*/
     return trim($this->template->renderBlock($block, $cell->vars));
 }
开发者ID:ekyna,项目名称:table,代码行数:15,代码来源:TableExtension.php

示例8: sendMessage

 /**
  * {@inheritdoc}
  */
 public function sendMessage($text, UserInterface $user, \Twig_Template $twigTemplate, array $parameters)
 {
     if ($user instanceof EmailAwareUserInterface) {
         if (!$user->getEmail()) {
             return false;
         }
         $subject = $twigTemplate->renderBlock('subject', $parameters);
         if (!$subject) {
             throw new \Exception('Subject not defined');
         }
         $body = $twigTemplate->renderBlock('body_email_text', $parameters);
         $emailMessage = \Swift_Message::newInstance();
         $emailMessage = $emailMessage->setSubject($subject)->setFrom($this->sender)->setTo($user->getEmail())->setBody($body);
         /** @var \Swift_Message $emailMessage */
         $emailMessage = $emailMessage->addPart($text, 'text/html');
         return $this->mailer->send($emailMessage);
     }
     return null;
 }
开发者ID:Werkint,项目名称:NotificationBundle,代码行数:22,代码来源:EmailHandler.php

示例9: renderCell

 /**
  * @inheritdoc
  */
 public function renderCell(ListingColumnTypeInterface $column, $row)
 {
     if (!$this->loaded) {
         $this->load();
     }
     // Load and process value:
     $values = $column->getValues($row);
     //$value = $this->normalizeValue($value, $column->getOptions());
     // Create template block name and parameters:
     $blockName = 'listing_' . $column->getType();
     $parameters = array_merge(array('column' => $column, 'row' => $row), $values);
     // Render block:
     return trim($this->template->renderBlock($blockName, $parameters, $this->blocks));
 }
开发者ID:rebornlab,项目名称:DataTablesListing,代码行数:17,代码来源:ListingRenderer.php

示例10: preparedMessage

 /**
  * @param string $email
  * @param array $parameters
  * @return \Swift_Message
  */
 private function preparedMessage($email, $parameters)
 {
     $message = new \Swift_Message();
     $message->setTo($email);
     $message->setFrom($this->template->renderBlock('from', $parameters), $this->template->renderBlock('from_name', $parameters));
     $message->setSubject($this->template->renderBlock('subject', $parameters));
     $message->setBody($this->template->renderBlock('body_text', $parameters));
     $message->addPart($this->template->renderBlock('body_html', $parameters), 'text/html');
     return $message;
 }
开发者ID:cgrandval,项目名称:opencfp,代码行数:15,代码来源:ResetEmailer.php

示例11: renderBlock

 /**
  * Renders a Twig block.
  *
  * see {@link https://github.com/twigphp/Twig/issues/676#issuecomment-15842093}
  *
  * @param \Twig_Template $template
  * @param string         $block
  * @param array          $context
  *
  * @return string
  *
  * @throws \Exception
  */
 private function renderBlock(\Twig_Template $template, $block, array $context)
 {
     $context = $template->getEnvironment()->mergeGlobals($context);
     $level = ob_get_level();
     ob_start();
     try {
         $rendered = $template->renderBlock($block, $context);
         ob_end_clean();
         return $rendered;
     } catch (\Exception $e) {
         while (ob_get_level() > $level) {
             ob_end_clean();
         }
         throw $e;
     }
 }
开发者ID:jvasseur,项目名称:mail-sender,代码行数:29,代码来源:MailSender.php

示例12: renderField

 /**
  * Renders the HTML for a given field.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Content $content
  * @param string $fieldIdentifier Identifier for the field we want to render
  * @param array $params An array of parameters to pass to the field view
  *
  * @throws InvalidArgumentException
  * @return string The HTML markup
  */
 public function renderField(Content $content, $fieldIdentifier, array $params = array())
 {
     $field = $this->translationHelper->getTranslatedField($content, $fieldIdentifier, isset($params['lang']) ? $params['lang'] : null);
     if (!$field instanceof Field) {
         throw new InvalidArgumentException('$fieldIdentifier', "Invalid for content #{$content->contentInfo->id} '{$content->contentInfo->name}'");
     }
     $localTemplate = null;
     if (isset($params['template'])) {
         // local override of the template
         // this template is put on the top the templates stack
         $localTemplate = $params['template'];
         unset($params['template']);
     }
     $params = $this->getRenderFieldBlockParameters($content, $field, $params);
     // Getting instance of Twig_Template that will be used to render blocks
     if (!$this->template instanceof Twig_Template) {
         $tpl = reset($this->renderFieldResources);
         $this->template = $this->environment->loadTemplate($tpl['template']);
     }
     return $this->template->renderBlock($this->getRenderFieldBlockName($content, $field), $params, $this->getBlocksByField($content, $field, $localTemplate));
 }
开发者ID:blankse,项目名称:ezpublish-kernel-1,代码行数:31,代码来源:ContentExtension.php

示例13: renderArticleLocales

 /**
  * @param  \ServerGrove\KbBundle\Document\Article $article
  * @return string
  */
 public function renderArticleLocales(Article $article)
 {
     return $this->twig->renderBlock('article_locales', array('article' => $article, 'locales' => $this->locales));
 }
开发者ID:Cohros,项目名称:KnowledgeBase,代码行数:8,代码来源:ArticleExtension.php

示例14: render

 /**
  * Render block $block with $table view's data.
  * @param \Twig_Environment $twig
  * @param \EMC\TableBundle\Table\TableView $view
  * @param string $block
  * @return string
  */
 public function render(\Twig_Environment $twig, TableView $view, $block)
 {
     $this->load();
     return $this->template->renderBlock($block, $view->getData());
 }
开发者ID:cwd,项目名称:TableBundle,代码行数:12,代码来源:TableExtension.php

示例15: getChildrenValues

 /**
  * @param \SimpleXMLIterator $element
  * @param \Twig_Template     $template
  *
  * @param string             $formId
  * @param string             $xPath
  * @param string             $requiredChildren
  * @param array              $identityRefs
  *
  * @return array|bool
  */
 public function getChildrenValues($element, $template, $formId, $xPath = "", $requiredChildren = "", $identityRefs = array())
 {
     $retArr = array();
     $targetAttributes = array('key', 'iskey', 'mandatory');
     foreach ($element as $label => $el) {
         $attributesArr = array_fill_keys($targetAttributes, false);
         foreach ($element->attributes() as $name => $attr) {
             if ($name == "key") {
                 $attributesArr[$name] = (string) $attr[0];
             }
         }
         foreach ($el->attributes() as $name => $attr) {
             if (in_array($name, array('iskey', 'mandatory'))) {
                 $attributesArr[$name] = (string) $attr[0];
             }
         }
         if (($attributesArr['iskey'] !== "true" && $attributesArr['key'] == false || $requiredChildren !== "" && $label != $requiredChildren) && $attributesArr['mandatory'] == false) {
             continue;
         }
         if ($attributesArr['key'] !== false) {
             $requiredChildren = $attributesArr['key'];
         } else {
             $requiredChildren = "";
         }
         $twigArr = array();
         $twigArr['key'] = "";
         $twigArr['xpath'] = "";
         $twigArr['element'] = $el;
         $twigArr['useHiddenInput'] = true;
         $twigArr['moduleIdentityRefs'] = $identityRefs;
         $newXPath = $xPath . "/*";
         $res = $this->getAvailableLabelValuesForXPath($formId, $newXPath);
         $retArr[$label] = array();
         if (isset($res['labelsAttributes'][$label])) {
             $retArr[$label]['labelAttributes'] = $res['labelsAttributes'][$label];
         }
         $retArr[$label]['valueElem'] = $this->removeMultipleWhitespaces($template->renderBlock('configInputElem', $twigArr));
         $retArr[$label]['children'] = $this->getChildrenValues($el, $template, $formId, $newXPath, $requiredChildren);
     }
     return sizeof($retArr) ? $retArr : false;
 }
开发者ID:Barathi07,项目名称:Netopeer-GUI,代码行数:52,代码来源:XMLoperations.php


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