All methods relies on a template name. A template name is a "logical" name for the template, and as such it does not refer to a path on the filesystem (in fact, the template can be stored anywhere, like in a database). The methods should accept any name. If the name is not an instance of TemplateReferenceInterface, a TemplateNameParserInterface should be used to convert the name to a TemplateReferenceInterface instance. Each template loader use the logical template name to look for the template.
Author: Fabien Potencier (fabien@symfony.com)
 public function onReviewerSubmitted(AssignReviewerEvent $event)
 {
     $reviewer = $event->getReviewer();
     $this->logger->debug('FASTCONFER: Asignado revisores a artículo: ' . $reviewer->getArticle()->getTitle());
     $message = $this->email->createMessage()->setSubject('You have Completed Registration!')->setFrom('*****@*****.**')->setTo($reviewer->getUser()->getEmail())->setBody($this->templating->render('email/assignReviewerEvent.html.twig', array('reviewer' => $reviewer)));
     $this->email->send($message);
 }
Beispiel #2
1
 public function getPdfContent($name, array $data = array())
 {
     $this->init();
     $tplFile = sprintf('%s:%s.pdf.twig', $this->options['tplShortDirectory'], $name);
     $htmlContent = $this->twig->render($tplFile, $data);
     $pdfContent = $this->snappy->getOutputFromHtml($htmlContent);
     return $pdfContent;
 }
 /**
  * @return string
  * @throws \Exception
  */
 public function render()
 {
     $this->checkLayoutData(__FUNCTION__);
     $this->passWidgetsToRenderer($this->layout_data);
     $rows = $this->convertGridstackToBootstrap($this->getLayoutData());
     return $this->templating->render($this->templates['front_layout'], array('rows' => $rows, 'renderer' => $this->widget_renderer));
 }
 /**
  * Returns the HTML for the namespace breadcrumbs
  *
  * @param array $options The user-supplied options from the view
  * @return string A HTML string
  */
 public function breadcrumbs(array $options = array())
 {
     $options = $this->resolveOptions($options);
     // Assign namespace breadcrumbs
     $options["breadcrumbs"] = $this->breadcrumbs->getNamespaceBreadcrumbs($options['namespace']);
     return $this->templating->render($options["viewTemplate"], $options);
 }
 /**
  * @inheritdoc
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     /** @var ChoiceView $choice */
     foreach ($view->vars['choices'] as $choice) {
         if ($options['select2_template_result']) {
             $object = $choice->value;
             if ($this->doctrine && $options['class']) {
                 $object = $this->doctrine->getRepository($options['class'])->find($object);
             }
             if (is_string($options['select2_template_result'])) {
                 $choice->attr['data-template-result'] = $this->templating->render($options['select2_template_result'], ['choice' => $choice, 'object' => $object]);
             } else {
                 $choice->attr['data-template-result'] = call_user_func_array($options['select2_template_result'], [$choice, $object]);
             }
         }
         if ($options['select2_template_selection']) {
             $object = $choice->value;
             if ($this->doctrine && $options['class']) {
                 $object = $this->doctrine->getRepository($options['class'])->find($object);
             }
             if (is_string($options['select2_template_selection'])) {
                 $choice->attr['data-template-selection'] = $this->templating->render($options['select2_template_selection'], ['choice' => $choice, 'object' => $object]);
             } else {
                 $choice->attr['data-template-selection'] = call_user_func_array($options['select2_template_selection'], [$choice, $object]);
             }
         }
     }
     if ($options['select2'] === true) {
         $options['select2_options'] = array_merge($this->select2DefaultOptions, $options['select2_options']);
         $view->vars['select2_options'] = json_encode($options['select2_options']);
     }
 }
 /**
  * Renders the legacy website toolbar template.
  *
  * If the logged in user doesn't have the required permission, an empty response is returned
  *
  * @param mixed $locationId
  * @param Request $request
  *
  * @return Response
  */
 public function websiteToolbarAction($locationId, Request $request)
 {
     $response = new Response();
     if (isset($this->csrfProvider)) {
         $parameters['form_token'] = $this->csrfProvider->generateCsrfToken('legacy');
     }
     if ($this->previewHelper->isPreviewActive()) {
         $template = 'design:parts/website_toolbar_versionview.tpl';
         $previewedContent = $authValueObject = $this->previewHelper->getPreviewedContent();
         $previewedVersionInfo = $previewedContent->versionInfo;
         $parameters = array('object' => $previewedContent, 'version' => $previewedVersionInfo, 'language' => $previewedVersionInfo->initialLanguageCode, 'is_creator' => $previewedVersionInfo->creatorId === $this->getRepository()->getCurrentUser()->id);
     } elseif ($locationId === null) {
         return $response;
     } else {
         $authValueObject = $this->loadContentByLocationId($locationId);
         $template = 'design:parts/website_toolbar.tpl';
         $parameters = array('current_node_id' => $locationId, 'redirect_uri' => $request->attributes->get('semanticPathinfo'));
     }
     $authorizationAttribute = new AuthorizationAttribute('websitetoolbar', 'use', array('valueObject' => $authValueObject));
     if (!$this->authChecker->isGranted($authorizationAttribute)) {
         return $response;
     }
     $response->setContent($this->legacyTemplateEngine->render($template, $parameters));
     return $response;
 }
 /**
  * Renders a PDF using the Templating engine
  *
  * @param string $name       The name of the template
  * @param array $parameters  An array of parameters to pass to the template
  * @param array $options     Options to be used when creating the new PDF
  *
  * @return \TCPDF
  */
 public function renderPdf($name, array $parameters = array(), array $options = array())
 {
     $html = $this->templatingEngine->render($name, $parameters);
     $pdf = $this->pdfFactory->create($options);
     $pdf->writeHTML($html);
     return $pdf;
 }
 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $nodeTranslation = $request->attributes->get('_nodeTranslation');
     if ($nodeTranslation) {
         $entity = $request->attributes->get('_entity');
         $url = $request->attributes->get('url');
         $nodeMenu = $request->attributes->get('_nodeMenu');
         $parameters = $request->attributes->get('_renderContext');
         if ($request->get('preview') == true) {
             $version = $request->get('version');
             if (!empty($version) && is_numeric($version)) {
                 $nodeVersion = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion')->find($version);
                 if (!is_null($nodeVersion)) {
                     $entity = $nodeVersion->getRef($this->em);
                 }
             }
         }
         $renderContext = array('nodetranslation' => $nodeTranslation, 'slug' => $url, 'page' => $entity, 'resource' => $entity, 'nodemenu' => $nodeMenu);
         if (is_array($parameters) || $parameters instanceof \ArrayObject) {
             $parameters = array_merge($renderContext, (array) $parameters);
         } else {
             $parameters = $renderContext;
         }
         // Sent the response here, another option is to let the symfony kernel.view listener handle it
         $event->setResponse($this->templating->renderResponse($entity->getDefaultView(), $parameters));
     }
 }
Beispiel #9
0
 private function sendConfirmMail(Configuration $configuration, ContactInterface $model)
 {
     $text = $this->templating->render($configuration->getConfirmTemplate(), ['data' => $model]);
     $subject = $this->translator->trans($configuration->getSubject(), [], $configuration->getTranslationDomain());
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($configuration->getFrom())->setTo($model->getEmail())->setBody($text, 'text/html');
     $this->mailer->send($message);
 }
 public function listAction()
 {
     $data = $this->repository->getList();
     $entries = array();
     $dayId = 0;
     foreach ($data as $entry) {
         $timestamp = $entry->getTimestamp()->getTimestamp();
         $dateTime = new \DateTime();
         $dateTime->setTimestamp($timestamp);
         $dateTime->setTime(0, 0);
         $currentDay = $dateTime->getTimestamp();
         if (!isset($entries[$currentDay])) {
             //init day
             $entries[$currentDay] = array();
             $entries[$currentDay]['entries'] = array();
             $entries[$currentDay]['id'] = $dayId++;
             $entries[$currentDay]['date'] = date('l, d. F', $currentDay);
             $entries[$currentDay]['grapharray'] = "{}";
         }
         $entries[$currentDay]['entries'][] = array("id" => $entry->getId(), "timestamp" => $timestamp, "time" => date('H:i', $timestamp), "value" => $entry->getValue(), "insulin" => $entry->getInsulin(), "BE" => $entry->getBE(), "key" => $entry->getTimestamp());
     }
     $entries = $this->augmentGraphData($entries);
     $entries = array_reverse($entries);
     return new Response($this->templating->render('Diaborg3Bundle:List:list.html.twig', array("entries" => $entries)));
 }
 /**
  * @return Response
  */
 public function overviewAction()
 {
     $this->guard->userIsLoggedIn();
     $this->logger->notice('Showing My Profile page');
     $user = $this->userService->getUser();
     return new Response($this->templateEngine->render('OpenConextProfileBundle:MyProfile:overview.html.twig', ['user' => $user]));
 }
 public function render(CantigaController $controller, Request $request, Workspace $workspace, Project $project = null)
 {
     $rootEntity = $controller->getMembership()->getItem();
     $this->repository->setRootEntity($rootEntity);
     $this->settingsRepository->setRootEntity($rootEntity);
     return $this->templating->render('WioEdkBundle:Extension:route-summary.html.twig', ['routeNum' => $this->repository->countRoutes(), 'participantNum' => $this->settingsRepository->countParticipants()]);
 }
 function it_can_be_transformed(EngineInterface $templating, FilterChainInterface $filterChain, MailUserInterface $recipient1, MailUserInterface $recipient2, Attachment $attachment)
 {
     $html = '<html><head></head><body>Test</body></html>';
     $templating->render(Argument::type('string'), Argument::type('array'))->willReturn($html);
     $filterChain->apply(Argument::type('string'), Argument::any())->willReturn($html);
     $recipient1->getFullName()->willReturn('Test recipient 1');
     $recipient1->getEmail()->willReturn('*****@*****.**');
     $recipient2->getFullName()->willReturn('Test recipient 2');
     $recipient2->getEmail()->willReturn('*****@*****.**');
     $attachmentFileName = 'test.txt';
     $attachment->getData()->willReturn('test');
     $attachment->getFilename()->willReturn($attachmentFileName);
     $attachment->getContentType()->willReturn('text');
     $this->addRecipients([$recipient1, $recipient2]);
     $this->addBccRecipients([$recipient1, $recipient2]);
     $this->addAttachment($attachment);
     $message = $this->transform($templating, $filterChain, array(array('view' => 'default', 'contentType' => 'text/html')));
     $message->shouldHaveType('\\Swift_Message');
     $message->getSubject()->shouldBeLike(self::SUBJECT);
     $message->getBody()->shouldBeLike($html);
     $message->getFrom()->shouldBeLike(array(self::SENDER_EMAIL => self::SENDER_NAME));
     $message->getTo()->shouldHaveCount(2);
     $message->getBcc()->shouldHaveCount(2);
     $message->getChildren()->shouldHaveCount(1);
     // 1 attachment
     $attachment = $message->getChildren()[0];
     $attachment->shouldHaveType('Swift_Mime_Attachment');
     $attachment->getFileName()->shouldBeLike($attachmentFileName);
 }
Beispiel #14
0
 public function sendMail(\Exception $exception, Request $request, array $context, $needToFlush)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     if (!$this->_hasInitialized) {
         $this->_initialize();
     }
     $params = array('exception' => $exception, 'request' => $request, 'context' => $context, 'status_text' => Response::$statusTexts[$exception->getStatusCode()]);
     $preMailEvent = new GenericEvent($params, array('shouldSend' => true));
     $this->_eventDispatcher->dispatch('ehough.bundle.emailErrors.preMail', $preMailEvent);
     if (!$preMailEvent->getArgument('shouldSend')) {
         //mail was cancelled
         return;
     }
     $body = $this->_templatingEngine->render('EhoughEmailErrorsBundle::mail.html.twig', $params);
     $subject = '[' . $request->headers->get('host') . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage();
     if (function_exists('mb_substr')) {
         $subject = mb_substr($subject, 0, 255);
     } else {
         $subject = substr($subject, 0, 255);
     }
     $mail = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->_fromAddress)->setTo($this->_toAddress)->setContentType('text/html')->setBody($body);
     $this->_mailer->send($mail);
     if ($needToFlush) {
         $this->_flushEmailer();
     }
 }
    /**
     * Renders the template with provided options.
     * "template" option allows to override the default template for rendering.
     *
     * @param array $options
     * @return string
     */
    protected function doRender( array $options )
    {
        $template = isset( $options['template'] ) ? $options['template'] : $this->getDefaultTemplate();
        unset( $options['template'] );

        return $this->templateEngine->render( $template, $options );
    }
 /**
  * Flushes messages
  */
 public function flush()
 {
     foreach ($this->pendingEmails as $email) {
         $message = \Swift_Message::newInstance()->setSubject($this->translator->trans($email->getSubject()))->setFrom($this->from)->setTo($email->getSendTo())->setBody($this->templating->render($email->getTemplate(), $email->getData()));
         $this->mailer->send($message, $failedRecipients);
     }
     $this->clear();
 }
 /**
  * {@inheritdoc}
  */
 public function render(\Exception $exception, BlockInterface $block, Response $response = null)
 {
     $parameters = array('exception' => $exception, 'block' => $block);
     $content = $this->templating->render($this->template, $parameters);
     $response = $response ?: new Response();
     $response->setContent($content);
     return $response;
 }
 public function setUp()
 {
     $this->configResolver = $this->getMockBuilder('\\eZ\\Publish\\Core\\MVC\\ConfigResolverInterface')->getMock();
     $this->configResolver->method('getParameter')->willReturn('Tests/fixtures/template_module.js');
     $this->templating = $this->getMockBuilder('\\Symfony\\Component\\Templating\\EngineInterface')->getMock();
     $this->templating->method('render')->willReturn('template');
     $this->comboLoader = new ComboLoader($this->configResolver, $this->templating, '/yui/', 'Tests/fixtures');
 }
 public function handleCookieConsent(FilterResponseEvent $event)
 {
     if (!$event->isMasterRequest() || $event->getRequest()->cookies->has($this->cookieName)) {
         return;
     }
     $response = $event->getResponse();
     $response->setContent($response->getContent() . $this->templating->render($this->cookieTemplate));
 }
Beispiel #20
0
 public function render($type = 'search', $entities = null, $fields = null)
 {
     if ($this->templateEngine === null) {
         $this->templateEngine = $this->container->get('templating');
     }
     $template = $this->container->getParameter('enhavo_search.' . $type . '.template');
     return $this->templateEngine->render($template, array('type' => $type, 'entities' => $entities, 'fields' => $fields));
 }
 public function render(CantigaController $controller, Request $request, Area $area)
 {
     $data = $area->getCustomData();
     if (!empty($data['positionLat']) && !empty($data['positionLng'])) {
         return $this->templating->render('WioEdkBundle:Extension:area-information-map.html.twig', ['positionLat' => $data['positionLat'], 'positionLng' => $data['positionLng']]);
     }
     return '';
 }
 /**
  * Tries to load the resource for a block from a theme.
  *
  * @param string $cacheKey  The cache key for storing the resource.
  * @param string $blockName The name of the block to load a resource for.
  * @param mixed  $theme     The theme to load the block from.
  *
  * @return bool    True if the resource could be loaded, false otherwise.
  */
 protected function loadResourceFromTheme($cacheKey, $blockName, $theme)
 {
     if ($this->engine->exists($templateName = $theme . '/' . $blockName . '.html.php')) {
         $this->resources[$cacheKey][$blockName] = $templateName;
         return true;
     }
     return false;
 }
 public function render(CantigaController $controller, Request $request, Workspace $workspace, Project $project = null)
 {
     $text = $this->textRepository->getTextOrFalse('cantiga:dashboard:' . $workspace->getKey(), $request, $project);
     if (false === $text) {
         return '';
     }
     return $this->templating->render('CantigaCoreBundle:AppText:dashboard-element.html.twig', ['text' => $text]);
 }
 public function testRequestHtml()
 {
     $expectedResponse = new Response('some-html-string');
     $this->templating->expects($this->once())->method('render')->will($this->returnValue($expectedResponse));
     /** @var Response $response */
     $response = $this->controller->indexAction('html', 'test');
     $this->assertEquals($expectedResponse, $response->getContent());
 }
 public function render(CantigaController $controller, Request $request, Workspace $workspace, Project $project = null)
 {
     if ($controller->getProjectSettings()->get(CoreSettings::DASHOBARD_SHOW_REQUESTS)->getValue()) {
         $this->repository->setActiveProject($project);
         return $this->templating->render('CantigaCoreBundle:Project:recent-area-requests.html.twig', ['requests' => $this->repository->getRecentRequests(5)]);
     }
     return '';
 }
 public function testRender()
 {
     $view = $this->createView();
     $view->setTemplateIdentifier('path/to/template.html.twig');
     $this->eventDispatcherMock->expects($this->once())->method('dispatch')->with(MVCEvents::PRE_CONTENT_VIEW, $this->isInstanceOf('\\eZ\\Publish\\Core\\MVC\\Symfony\\Event\\PreContentViewEvent'));
     $this->templateEngineMock->expects($this->once())->method('render')->with('path/to/template.html.twig', $view->getParameters());
     $this->renderer->render($view);
 }
 /**
  * @return Metadata
  */
 public function generate()
 {
     $metadata = $this->getMetadata();
     $keyPair = $this->buildKeyPairFrom($this->metadataConfiguration);
     $metadata->document = SAML2_DOMDocumentFactory::create();
     $metadata->document->loadXML($this->templateEngine->render('SurfnetSamlBundle:Metadata:metadata.xml.twig', ['metadata' => $metadata]));
     $this->signingService->sign($metadata, $keyPair);
     return $metadata;
 }
 /**
  * Payment execution.
  *
  * @return Response
  */
 public function executeAction()
 {
     /**
      * The execute action will generate the Redsys
      * checkout form before redirecting
      */
     $formView = $this->redsysManager->processPayment();
     return new Response($this->templatingEngine->render('RedsysBundle:Redsys:process.html.twig', ['redsys_form' => $formView]));
 }
Beispiel #29
0
 /**
  * {@inheritdoc}
  */
 public function render(ReportInterface $report, Data $data)
 {
     if (null !== $data->getData()) {
         $data = array('report' => $report, 'values' => $data->getData(), 'labels' => $data->getLabels(), 'fields' => array_keys($data->getData()));
         $rendererConfiguration = $report->getRendererConfiguration();
         return $this->templating->render($rendererConfiguration["template"], array('data' => $data, 'configuration' => $rendererConfiguration));
     }
     return $this->templating->render("SyliusReportBundle::noDataTemplate.html.twig", array('report' => $report));
 }
Beispiel #30
-1
 public function export(Portfolio $portfolio, $format)
 {
     if (!in_array($format, $this->availableFormats)) {
         throw new \InvalidArgumentException('Unknown format.');
     }
     return $this->templatingEngine->render(sprintf('IcapPortfolioBundle:export:export.%s.twig', $format), array('portfolio' => $portfolio));
 }