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


PHP Twig_Environment::loadTemplate方法代码示例

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


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

示例1: create

 /**
  * {@inheritdoc}
  */
 public function create($templateName, array $context = array())
 {
     if (!isset($this->templateConfigs[$templateName])) {
         throw new TemplateNotExistsException($templateName);
     }
     $templateConfig = $this->templateConfigs[$templateName];
     if (isset($context['utm'])) {
         $templateConfig['utm'] = array_merge($templateConfig['utm'], $context['utm']);
     }
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateConfig['template']);
     $subject = $template->renderBlock('subject', $context);
     $htmlBody = $template->renderBlock('body_html', $context);
     $textBody = $template->renderBlock('body_text', $context);
     if (empty($subject)) {
         throw new TemplatePartRequiredException('subject', $templateConfig['template']);
     }
     if (empty($htmlBody)) {
         throw new TemplatePartRequiredException('body_html', $templateConfig['template']);
     }
     $htmlBody = $this->cssToInline($htmlBody);
     $htmlBody = $this->addUtmParams($htmlBody, $templateConfig['host'], $templateConfig['utm']);
     if (empty($textBody) && $templateConfig['generate_text_version']) {
         $textBody = $this->htmlToText($htmlBody);
     }
     $message = \Swift_Message::newInstance()->setSubject($subject)->setBody($htmlBody, 'text/html');
     if (!empty($textBody)) {
         $message->addPart($textBody, 'text/plain');
     }
     return $message;
 }
开发者ID:fullpipe,项目名称:email-template-bundle,代码行数:34,代码来源:MessageFactory.php

示例2: send

 /**
  * @param string $name
  * @param array  $context
  * @param callable|null $callback a callback to modify the mail before it is sent.
  */
 public function send($name, array $context = [], callable $callback = null)
 {
     $template = $this->twig->loadTemplate($name);
     $blocks = [];
     foreach (['from', 'from_name', 'to', 'to_name', 'subject', 'body_txt', 'body_html'] as $blockName) {
         $rendered = $this->renderBlock($template, $blockName, $context);
         if ($rendered) {
             $blocks[$blockName] = $rendered;
         }
     }
     $blocks = array_merge($context, $blocks);
     $mail = new \Swift_Message();
     $mail->setSubject($blocks['subject']);
     $mail->setFrom(isset($blocks['from_name']) ? [$blocks['from'] => $blocks['from_name']] : $blocks['from']);
     if (isset($blocks['to'])) {
         $mail->setTo(isset($blocks['to_name']) ? [$blocks['to'] => $blocks['to_name']] : $blocks['to']);
     }
     if (isset($blocks['body_txt']) && isset($blocks['body_html'])) {
         $mail->setBody($blocks['body_txt']);
         $mail->addPart($blocks['body_html'], 'text/html');
     } elseif (isset($blocks['body_txt'])) {
         $mail->setBody($blocks['body_txt']);
     } elseif (isset($blocks['body_html'])) {
         $mail->setBody($blocks['body_html'], 'text/html');
     }
     if ($callback) {
         $callback($mail);
     }
     $this->mailer->send($mail);
 }
开发者ID:jvasseur,项目名称:mail-sender,代码行数:35,代码来源:MailSender.php

示例3: __construct

 /**
  * Load a template.
  * @param string $template
  * @param string $namespace
  */
 public function __construct($template, $namespace = null)
 {
     if (!self::$initialised) {
         self::init();
     }
     $template = $template . '.twig';
     if (!is_null($namespace)) {
         $template = '@' . $namespace . '/' . $template;
     }
     $this->templateName = $template;
     $this->template = self::$twig->loadTemplate($template);
     Event::trigger('Template.Loaded', $this);
     switch ($namespace) {
         case 'db':
             // Do nothing
             break;
         case 'admin':
             Event::trigger('Template.Loaded.Admin', $this);
             break;
         default:
             Event::trigger('PublicTemplateLoaded', $this);
             Event::trigger('Template.Loaded.Public', $this);
             break;
     }
 }
开发者ID:block8,项目名称:octo,代码行数:30,代码来源:Template.php

示例4: sendMail

 /**
  * Sends an email
  *
  * @param string $recipient
  * @param string $templatePath Path to the twig template
  * @param array $data
  * @param array $blindCopyRecipients Recipients to send bcc
  *
  * @return bool
  */
 public function sendMail($recipient, $templatePath, $data = array(), $blindCopyRecipients = array())
 {
     $tmplData = array_merge($data, array('footerTxt' => $this->templateFooterTxtPath, 'footerHtml' => $this->templateFooterHtmlPath));
     // Load template from twig.
     $template = $this->twig->loadTemplate($templatePath);
     // Merge twig globals so that they also are available in renderBlock.
     $tmplData = $this->twig->mergeGlobals($tmplData);
     // Get subject from block.
     $subject = $template->renderBlock('subject', $tmplData);
     $emailBodyText = $template->renderBlock('body_text', $tmplData);
     $emailBodyHtml = $template->renderBlock('body_html', $tmplData);
     /** @var \Swift_Message $message */
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->emailFrom)->setTo($recipient)->setBody($emailBodyText, 'text/plain')->addPart($emailBodyHtml, 'text/html');
     // add blind copy recipients
     foreach ($blindCopyRecipients as $bcc) {
         $message->addBcc($bcc);
     }
     $failedRecipients = array();
     $this->mailer->send($message, $failedRecipients);
     if (count($failedRecipients) > 0) {
         $this->writeLog('Could not send mail to the following recipients: ' . join(', ', $failedRecipients));
         return false;
     }
     return true;
 }
开发者ID:sulu,项目名称:sulu-sales,代码行数:35,代码来源:EmailManager.php

示例5: 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

示例6: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array(__DIR__ . '/../../Resources/views/Form')));
     $this->twig->addExtension(new CKEditorExtension($this->helper));
     $this->template = $this->twig->loadTemplate('ckeditor_widget.html.twig');
 }
开发者ID:Chaireeee,项目名称:chaireeee,代码行数:10,代码来源:TwigTemplateTest.php

示例7: _getTemplateResource

 protected final function _getTemplateResource($template)
 {
     if (!isset($this->__templateResources[$template])) {
         $this->__templateResources[$template] = $this->environment->loadTemplate($template);
     }
     return $this->__templateResources[$template];
 }
开发者ID:mikegibson,项目名称:sentient,代码行数:7,代码来源:TemplateBlockRenderer.php

示例8: getIconTemplate

 /**
  * @return \Twig_TemplateInterface $template
  */
 protected function getIconTemplate()
 {
     if ($this->iconTemplate === null) {
         $this->iconTemplate = $this->environment->loadTemplate('@MopaBootstrap/icons.html.twig');
     }
     return $this->iconTemplate;
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:10,代码来源:IconExtension.php

示例9: onRequestedPassword

 /**
  * @param UserDataEvent $event
  */
 public function onRequestedPassword(UserDataEvent $event)
 {
     $user = $event->getUser();
     $token = $this->tokenGenerator->generateToken();
     $this->userManager->updateConfirmationTokenUser($user, $token);
     $message = \Swift_Message::newInstance()->setCharset('UTF-8')->setSubject($this->templating->loadTemplate($this->template)->renderBlock('subject', []))->setFrom($this->from)->setTo($user->getEmail())->setBody($this->templating->loadTemplate($this->template)->renderBlock('body', ['username' => $user->getUsername(), 'request_link' => $this->router->generate('reset_password', ['token' => $token], true)]));
     $this->mailer->send($message);
 }
开发者ID:jpsymfony,项目名称:REST-BEHAT,代码行数:11,代码来源:SendRequestPasswordMailListener.php

示例10: loadFile

 /**
  * @param FileParameter $Location
  * @param bool          $Reload
  *
  * @return IBridgeInterface
  */
 public function loadFile(FileParameter $Location, $Reload = false)
 {
     $this->Instance = new \Twig_Environment(new \Twig_Loader_Filesystem(array(dirname($Location->getFile()))), array('auto_reload' => $Reload, 'autoescape' => false, 'cache' => realpath(__DIR__ . '/TwigTemplate')));
     $this->Instance->addFilter(new \Twig_SimpleFilter('utf8_encode', 'utf8_encode'));
     $this->Instance->addFilter(new \Twig_SimpleFilter('utf8_decode', 'utf8_decode'));
     $this->Template = $this->Instance->loadTemplate(basename($Location->getFile()));
     return $this;
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:14,代码来源:TwigTemplate.php

示例11: getTemplates

 /**
  * Gets the templates for a given profile.
  *
  * @param \Symfony\Component\HttpKernel\Profiler\Profile $profile
  *
  * @return array
  */
 public function getTemplates(Profile $profile)
 {
     $templates = $this->getNames($profile);
     foreach ($templates as $name => $template) {
         $templates[$name] = $this->twig->loadTemplate($template);
     }
     return $templates;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:15,代码来源:TemplateManager.php

示例12: renderIndexablePageParts

 /**
  * @param array                 $twigContext The twig context
  * @param HasPagePartsInterface $page        The page
  * @param string                $contextName The pagepart context
  * @param array                 $parameters  Some extra parameters
  *
  * @return string
  */
 public function renderIndexablePageParts(array $twigContext, HasPagePartsInterface $page, $contextName = 'main', array $parameters = array())
 {
     $template = $this->environment->loadTemplate('KunstmaanNodeSearchBundle:PagePart:view.html.twig');
     $pageparts = $this->indexablePagePartsService->getIndexablePageParts($page, $contextName);
     $newTwigContext = array_merge($parameters, array('pageparts' => $pageparts));
     $newTwigContext = array_merge($newTwigContext, $twigContext);
     return $template->render($newTwigContext);
 }
开发者ID:headonkeyboard,项目名称:KunstmaanBundlesCMS,代码行数:16,代码来源:KunstmaanNodeSearchTwigExtension.php

示例13: sendNotification

 /**
  * sendNotification.
  *
  * @param string $templateName
  * @param array  $context
  */
 private function sendNotification($templateName, array $context)
 {
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateName);
     $message = $template->renderBlock('body', $context);
     $notification = new Notification($message);
     $this->notifier->notify($notification);
 }
开发者ID:hogosha,项目名称:hogosha,代码行数:14,代码来源:NotificationCenter.php

示例14: run

 public function run()
 {
     $scanner = new ModuleScanner();
     $modules = $scanner->getModules();
     $template = $this->twig->loadTemplate("modules.twig");
     $output = $template->render(["modules" => $modules]);
     print $output;
 }
开发者ID:adamjakab,项目名称:D8ModScan,代码行数:8,代码来源:Application.php

示例15: send

 /**
  * {@inheritdoc}
  */
 public function send($template, array $recipients, array $data = array())
 {
     $data = $this->twig->mergeGlobals($data);
     $template = $this->twig->loadTemplate($template);
     $content = $template->renderBlock('content', $data);
     $originator = $template->renderBlock('originator', $data);
     $this->sender->send($recipients[0], $content, $originator);
 }
开发者ID:liverbool,项目名称:dos-user-bundle,代码行数:11,代码来源:Sender.php


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