renderToString() public method

Renders template to string.
public renderToString ( $name, array $params = [], $block = NULL ) : string
$params array
return string
Beispiel #1
0
 /**
  * 
  * @return CacheObject
  */
 public function render(CacheObject $file, Scripter $scripter)
 {
     $this->params['_scripter'] = $scripter;
     $this->params['_scripter_file_rendering'] = $file;
     $file->source = $this->latte->renderToString($file->path, $this->params);
     return $file;
 }
Beispiel #2
0
 /**
  * @param string $template
  * @param array $values
  * @return string
  */
 public function render($template, array $values = [])
 {
     if (!file_exists("{$this->basePath}/{$template}.latte")) {
         throw new FileNotFoundException();
     }
     return $this->latte->renderToString("{$this->basePath}/{$template}.latte", $values + $this->values);
 }
Beispiel #3
0
 /**
  * Prepares latte template for email
  *
  * @param string $path
  * @param array $variables
  *
  * @return string
  *
  * @throws InvalidArgumentException
  */
 private function createTemplate($path, $variables = [])
 {
     if (file_exists($path)) {
         return $this->engine->renderToString($path, $variables);
     } else {
         throw new InvalidArgumentException();
     }
 }
Beispiel #4
0
 public function render($toString = false)
 {
     if (!$toString) {
         self::$engine->render(__DIR__ . '/default.latte', $this->getParameters());
     } else {
         return self::$engine->renderToString(__DIR__ . '/default.latte', $this->getParameters());
     }
     return '';
 }
Beispiel #5
0
 /**
  * @param string $file
  */
 public function save($file = null)
 {
     $this->savePath = $file ?: $this->savePath;
     $dir = dirname($this->savePath);
     if (!is_dir($dir)) {
         mkdir($dir, 0755, true);
     }
     $content = $this->latteEngine->renderToString($this->file, $this->parameters);
     file_put_contents($this->savePath, $content);
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function render($template, array $values = [], $basePath = null)
 {
     if (!isset($basePath)) {
         $basePath = $this->basePath;
     }
     if (!file_exists("{$basePath}/{$template}")) {
         throw new FileNotFoundException("Cannot find the file, {$basePath}/{$template}");
     }
     return $this->latte->renderToString("{$basePath}/{$template}", $values + $this->values);
 }
 /**
  * @param string $path
  * @param array $params
  * @param bool $mustClean
  */
 public function render($path, $params, $mustClean = FALSE)
 {
     $this->initServices($params);
     // Render the view
     $content = $this->latte->renderToString($path, $params);
     if ($mustClean) {
         $this->_view->setContent($content);
     } else {
         echo $content;
     }
 }
Beispiel #8
0
 /**
  * Renders template to string.
  * @param  can throw exceptions? (hidden parameter)
  * @return string
  */
 public function __toString()
 {
     try {
         return $this->latte->renderToString($this->file, $this->params);
     } catch (\Exception $e) {
         if (func_num_args()) {
             throw $e;
         }
         trigger_error("Exception in " . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
     }
 }
Beispiel #9
0
 /**
  * Processes a view script and returns the output.
  *
  * @param  string|ModelInterface   $nameOrModel The script/resource process, or a view model
  * @param  null|array|\ArrayAccess $values      Values to use during rendering
  * @return string The script output.
  * @throws \LogicException
  */
 public function render($nameOrModel, $values = null)
 {
     $name = $nameOrModel;
     if ($nameOrModel instanceof ModelInterface) {
         $name = $this->resolver->resolve($nameOrModel->getTemplate(), $this);
         $values = (array) $nameOrModel->getVariables();
     }
     if (array_key_exists('helper', $values)) {
         throw new \LogicException('Variable $helper is reserved for Zend helpers and can\'t be passed to view.');
     }
     $values['helper'] = $this->helpers;
     return $this->engine->renderToString($name, $values);
 }
Beispiel #10
0
 public function sendMailConsumer(\PhpAmqpLib\Message\AMQPMessage $message)
 {
     $sendMail = json_decode($message->body);
     $latte = new Latte\Engine();
     $sendMail->templateArr->email = $sendMail->to;
     $sendMail->templateArr->subject = $sendMail->subject;
     if (!is_null($sendMail->unsubscribeLink)) {
         $sendMail->templateArr->unsubscribeLink = $sendMail->unsubscribeLink;
     }
     $mail = new Nette\Mail\Message();
     $mail->setFrom($sendMail->from)->addTo($sendMail->to)->setHtmlBody($latte->renderToString($this->config["appDir"] . $this->config['mailer']['templateDir'] . (is_null($sendMail->template) ? $this->config['mailer']['defaultTemplate'] : $sendMail->template), (array) $sendMail->templateArr));
     if (!is_null($sendMail->unsubscribeEmail) || !is_null($sendMail->unsubscribeLink)) {
         $mail->setHeader('List-Unsubscribe', (!is_null($sendMail->unsubscribeEmail) ? '<mailto:' . $sendMail->unsubscribeEmail . '>' : '') . (!is_null($sendMail->unsubscribeEmail) && !is_null($sendMail->unsubscribeLink) ? ", " : "") . (!is_null($sendMail->unsubscribeLink) ? '<' . $sendMail->unsubscribeLink . '>' : ''), TRUE);
     }
     $mail->setSubject($sendMail->subject);
     try {
         $mailer = $this->emailFactory->getConnection($sendMail->connection);
         $mailer->send($mail);
         dump($sendMail->to);
         if ($sendMail->imapSave) {
             $this->saveToImap($mail->generateMessage(), is_null($sendMail->imapFolder) ? $this->config['imap']['sendFolder'] : $sendMail->imapFolder, $sendMail->imapConnection);
         }
         return TRUE;
     } catch (\Exception $e) {
         return FALSE;
     }
 }
Beispiel #11
0
 /**
  * Gets html content
  *
  * @return mixed
  */
 public function getContent()
 {
     if (is_string($this->content) && file_exists($this->content)) {
         $latte = new Engine();
         return $latte->renderToString($this->content);
     }
     return (string) $this->content;
 }
Beispiel #12
0
 /**
  * @param string $email address
  * @param string $name
  * @throws Exception
  */
 public function sendBootstrap($email, $name)
 {
     $msg = new Message();
     $latte = new Engine();
     $args = ['email' => $msg];
     $html = $latte->renderToString($this->getTemplatePath('bootstrap'), $args);
     $msg->setFrom('*****@*****.**', 'Application Name')->addTo($email, $name)->setHtmlBody($html);
     $this->mailer->send($msg);
 }
Beispiel #13
0
 public function render($viewFile, $data, $return = false)
 {
     $latte = new Engine();
     $latte->setTempDirectory('runtime');
     if ($return) {
         return $latte->renderToString($viewFile, $data);
     } else {
         return $latte->render($viewFile, $data);
     }
 }
 /**
  * Renders HTML code for custom panel.
  *
  * @return string html
  * @internal
  */
 public function getPanel()
 {
     $latte = new Latte\Engine();
     $latte->addFilter('storageId', [$this, 'getStorageId']);
     $latte->addFilter('colorRange', [$this, 'getColorInRange']);
     $args = ['title' => $this->getTitle(), 'collector' => $this->collector];
     if ($this->collector->getQueries()) {
         $this->extremes = $this->collector->getTimeExtremes();
     }
     return $latte->renderToString(__DIR__ . '/queryPanel.latte', $args);
 }
 /**
  * @param Nette\Application\UI\Form $form
  */
 public function contactFormSubmitted(Nette\Application\UI\Form $form)
 {
     $values = $form->getValues();
     if ($this->context->getParameters()["send_emails"]) {
         $latte = new Engine();
         $mail = new Message();
         $mail->setFrom($this->context->getParameters()["mailer_mail"])->addTo($this->context->getParameters()["mailer_mail"])->setHtmlBody($latte->renderToString(__DIR__ . '/templates/Contact/email.latte', array("email" => $values->email, "content" => $values->content)));
         $mailer = new Nette\Mail\SmtpMailer(array('host' => $this->context->getParameters()["mailer_host"], 'username' => $this->context->getParameters()["mailer_mail"], 'password' => $this->context->getParameters()["mailer_password"], 'secure' => 'ssl'));
         $mailer->send($mail);
     }
     $this->redirect("Contact:sent");
 }
Beispiel #16
0
 public function addItem(IItem $item)
 {
     if (!$this->prepared) {
         $this->prepare();
     }
     if ($item->validate()) {
         $latte = new Latte\Engine();
         $xmlItem = $latte->renderToString($this->getTemplate('item'), ['product' => $item]);
         fwrite($this->handle, $xmlItem);
     } else {
         throw new ItemIncompletedException('Item is not complete');
     }
 }
 protected function buildFileFromTemplate($file, $template, $args = [], $prefix = '')
 {
     if (is_file($file)) {
         throw new InvalidStateException("File '{$file}' already exists");
     }
     $dir = dirname($file);
     if (!is_dir($dir)) {
         mkdir($dir);
     }
     $latte = new Engine();
     $content = $prefix . $latte->renderToString(__DIR__ . "/../scaffolds/{$template}.latte", $args);
     file_put_contents($file, $content);
 }
Beispiel #18
0
 /** Funkcia pre odoslanie emailu
  * @param array $params Parametre správy
  * @param string $subjekt Subjekt emailu
  * @return string Zoznam komu bol odoslany email
  * @throws SendException
  */
 public function send($params, $subjekt)
 {
     $templ = new Latte\Engine();
     $this->mail->setFrom($params["site_name"] . ' <' . $this->from . '>');
     $this->mail->setSubject($subjekt)->setHtmlBody($templ->renderToString($this->template, $params));
     try {
         $sendmail = new SendmailMailer();
         $sendmail->send($this->mail);
         return $this->email_list;
     } catch (Exception $e) {
         throw new SendException('Došlo k chybe pri odosielaní e-mailu. Skúste neskôr znovu...' . $e->getMessage());
     }
 }
Beispiel #19
0
 public function sendEmail($email = null, $latte_name, $product, $winners_bid, $cost, $title)
 {
     if ($email != null || $email != "") {
         // nastaveni parametru pro latte emailu
         $latte = new Latte\Engine();
         $params = array('product' => $product, 'winners_bid' => $winners_bid, 'cost' => $cost, 'title' => $title);
         // nastaveni mailu
         $mail = new Nette\Mail\Message();
         $mail->setFrom($this->mailer['username'])->addTo($email)->setHtmlBody($latte->renderToString(__DIR__ . '/../presenters/templates/Email/' . $latte_name . '.latte', $params));
         // poslani mailu
         $mailer = new Nette\Mail\SmtpMailer($this->mailer);
         $mailer->send($mail);
     }
 }
Beispiel #20
0
 /**
  * Gets html content
  *
  * @return string|Template
  */
 public function getContent()
 {
     if ($this->content instanceof Template) {
         // if is it template
         return $this->content->render();
     } else {
         if (file_exists($this->content)) {
             // if is it file
             $l = new Engine();
             return $l->renderToString($this->content);
         }
     }
     return (string) $this->content;
 }
 /**
  * Render a file
  *
  * @param string $file The file to render
  * @param array $locals The variable to use in template
  * @return null|string
  */
 public function renderFile($file, array $locals = array())
 {
     return $this->latte->renderToString($file, $locals);
 }
 /**
  * @throws \Exception
  * @return string|\Nette\Utils\Html
  */
 public function getControl()
 {
     $latte = new Engine();
     $params = ['editable' => $this->editable, 'control' => $this, 'input' => parent::getControl(), 'editors' => $this->getValue(), 'entity' => $this->entity, 'cascaded' => $this->getCascadedAllows()];
     return $latte->renderToString(__DIR__ . '/../../templates/controls/editorSelector.latte', $params);
 }
Beispiel #23
0
 /**
  * @param string $from
  * @param string $to
  * @param string $subject
  * @param string $link
  */
 private function sendEmail($from, $to, $subject, $link)
 {
     $latte = new Latte\Engine();
     $parameters = array('subject' => $subject, 'link' => $link);
     $email = new Message();
     $email->setFrom($from)->addTo($to)->setSubject($subject)->setHtmlBody($latte->renderToString($this->appDir . '/presenters/templates/emails/forgottenPassword.latte', $parameters));
     $this->mailer->send($email);
 }
Beispiel #24
0
 /**
  * Renders loaded files table.
  * @return string
  */
 private function getTable()
 {
     $latte = new Latte\Engine();
     $latte->addFilter('extension', function ($extension) {
         return isset(Panel::$types[$extension]) ? Panel::$types[$extension] : $extension;
     });
     return $latte->renderToString(__DIR__ . '/panel.latte', array('files' => $this->files, 'sizes' => $this->sizes, 'size' => $this->size));
 }
Beispiel #25
0
 public function userMailChangeFormSubmitted($button)
 {
     $values = $button->getForm()->getValues();
     //Nacitanie hodnot formulara
     $this->clen = $this->user_profiles->find($values->id);
     //Najdenie clena
     if (!$this->hasser->CheckPassword($values->heslo, $this->clen->users->password)) {
         $this->flashRedirect('this', $this->trLang('pass_incorect'), 'danger');
     }
     // Over, ci dany email uz existuje. Ak ano konaj.
     if ($this->users->testEmail($values->email)) {
         $this->flashMessage(sprintf($this->trLang('mail_change_email_duble'), $values->email), 'danger');
         return;
     }
     //Vygeneruj kluc pre zmenu e-mailu
     $email_key = $this->hasser->HashPassword($values->email . StrFTime("%Y-%m-%d %H:%M:%S", Time()));
     $clen = $this->user_profiles->find(1);
     //Najdenie odosielatela emailu
     $templ = new Latte\Engine();
     $params = ["site_name" => $this->nazov_stranky, "nadpis" => sprintf($this->trLang('email_change_mail_nadpis'), $this->nazov_stranky), "email_change_mail_txt" => sprintf($this->trLang('email_change_mail_txt'), $this->nazov_stranky), "email_change_mail_txt1" => $this->trLang('email_change_mail_txt1'), "email_nefunkcny_odkaz" => $this->trLang('email_nefunkcny_odkaz'), "email_pozdrav" => $this->trLang('email_pozdrav'), "nazov" => $this->trLang('mail_change'), "odkaz" => 'http://' . $this->nazov_stranky . $this->link("UserLog:activateNewEmail", $this->clen->id, $email_key)];
     $mail = new Message();
     $mail->setFrom($this->nazov_stranky . ' <' . $clen->users->email . '>')->addTo($values->email)->setSubject($this->trLang('mail_change'))->setHtmlBody($templ->renderToString(__DIR__ . '/templates/UserLog/email_change-html.latte', $params));
     try {
         $sendmail = new SendmailMailer();
         $sendmail->send($mail);
         $this->users->find($this->clen->id_users)->update(['new_email' => $values->email, 'new_email_key' => $email_key]);
         $this->flashRedirect('UserLog:', $this->trLang('mail_change_send_ok'), 'success');
     } catch (Exception $e) {
         $this->flashMessage($this->trLang('mail_change_send_err') . $e->getMessage(), 'danger');
     }
 }
Beispiel #26
0
 /** Spracovanie formulara
  * @param \Nette\Application\UI\Form $form
  */
 public function onZapisDotaz(Form $form)
 {
     $values = $form->getValues();
     //Nacitanie hodnot formulara
     $templ = new Latte\Engine();
     $params = array("nadpis" => sprintf('Správa z kontaktného formulará stránky %s', $this->nazov_stranky), "dotaz_meno" => sprintf('Užívateľ s menom %s poslal nasledujúcu správu:', $values->meno), "dotaz_text" => $values->text);
     $mail = new Message();
     $mail->setFrom($values->meno . ' <' . $values->email . '>')->addTo($this->emails)->setSubject(sprintf('Správa z kontaktného formulará stránky %s', $this->nazov_stranky))->setHtmlBody($templ->renderToString(__DIR__ . '/Kontakt_email-html.latte', $params));
     try {
         $sendmail = new SendmailMailer();
         $sendmail->send($mail);
         $this->presenter->flashMessage($this->text_form['send_ok'], 'success');
     } catch (Exception $e) {
         $this->presenter->flashMessage($this->text_form['send_er'] . $e->getMessage(), 'danger,n');
     }
     $this->redirect('this');
 }
Beispiel #27
0
 public function forgotPasswordFormSubmitted($button)
 {
     //Inicializacia
     $values = $button->getForm()->getValues();
     //Nacitanie hodnot formulara
     $clen = $this->users->findOneBy(['email' => $values->email]);
     $new_password_requested = StrFTime("%Y-%m-%d %H:%M:%S", Time());
     $new_password_key = $this->hasser->HashPassword($values->email . $new_password_requested);
     if (isset($clen->email) && $clen->email == $values->email) {
         //Taky clen existuje
         $templ = new Latte\Engine();
         $params = ["site_name" => $this->nazov_stranky, "nadpis" => sprintf($this->trLang('email_reset_nadpis'), $this->nazov_stranky), "email_reset_txt" => $this->trLang('email_reset_txt'), "email_nefunkcny_odkaz" => $this->trLang('email_nefunkcny_odkaz'), "email_pozdrav" => $this->trLang('email_pozdrav'), "nazov" => $this->trLang('forgot_pass'), "odkaz" => 'http://' . $this->nazov_stranky . $this->link("User:resetPassword", $clen->id, $new_password_key)];
         $mail = new Message();
         $mail->setFrom($this->nazov_stranky . ' <' . $this->clen->users->email . '>')->addTo($values->email)->setSubject($this->trLang('forgot_pass'))->setHtmlBody($templ->renderToString(__DIR__ . '/templates/User/forgot_password-html.latte', $params));
         try {
             $sendmail = new SendmailMailer();
             $sendmail->send($mail);
             $this->users->find($clen->id)->update(['new_password_key' => $new_password_key, 'new_password_requested' => $new_password_requested]);
             $this->flashMessage($this->trLang('forgot_pass_email_ok'), 'success');
         } catch (Exception $e) {
             $this->flashMessage($this->trLang('send_email_err') . $e->getMessage(), 'danger,n');
         }
         $this->redirect('Homepage:');
     } else {
         //Taky clen neexzistuje
         $this->flashMessage(sprintf($this->trLang('forgot_pass_user_err'), $values->email), 'danger');
     }
 }
 /**
  * @param string $view email template
  * @param User $user
  * @param NULL|array $args template variables
  *
  * @throws Exception from Latte\Engine
  * @throws SmtpException from Mailer
  */
 public function send($view, User $user, array $args = [])
 {
     if ($this->orm->unsubscribes->getByEmail($user->email)) {
         // Last line of defense. Make sure unsubscribed users
         // really dont receive any email. This should however
         // be handled before the task is queued.
         $this->logger->addAlert("Email to '{$user->email}' not send, user unsubscribed. Find out why it was queued");
         return;
     }
     $msg = new Message();
     $msg->setFrom('Khanova škola <*****@*****.**>');
     $msg->addReplyTo('Markéta Matějíčková <*****@*****.**>');
     $msg->addTo($user->email, $user->name);
     $token = Unsubscribe::createFromUser($user);
     $token->emailType = $view;
     $this->orm->tokens->attach($token);
     $this->orm->flush();
     $args['recipient'] = $user;
     $args['email'] = $msg;
     $args['unsubscribe'] = (object) ['token' => $token, 'code' => $token->getUnsafe()];
     $args['baseUrl'] = rtrim($this->baseUrl, '/');
     $latte = new Engine();
     /** @var Presenters\Token $presenter */
     $presenter = $this->factory->createPresenter('Token');
     $presenter->autoCanonicalize = FALSE;
     $ref = new \ReflectionProperty(Presenter::class, 'globalParams');
     $ref->setAccessible(TRUE);
     $ref->setValue($presenter, []);
     $latte->addFilter('token', function (Token $token, $unsafe) use($presenter, $view) {
         return $presenter->link('//Token:', ['token' => $token->toString($unsafe), 'utm_campaign' => "email-{$view}"]);
     });
     $latte->addFilter('vocative', function ($phrase) {
         return $this->inflection->inflect($phrase, 5);
     });
     $template = $latte->renderToString($this->getTemplate($view), $args);
     $msg->setHtmlBody($template);
     $this->mailer->send($msg);
     $this->logger->addInfo('Email send', ['view' => $view, 'email' => $user->email]);
 }
 public function render()
 {
     return $this->template->renderToString(__DIR__ . DIRECTORY_SEPARATOR . 'tree.latte', array('tree' => $this->tree, 'actionTemplatePath' => $this->actionTemplatePath, 'targetInputForChooser' => $this->targetInputForChooser, 'activeNode' => $this->activeNode));
 }
Beispiel #30
0
 /**
  * @param string $from
  * @param string $to
  * @param string $subject
  * @param string $link
  */
 private function sendEmail($from, $to, $subject, $link)
 {
     $latte = new Latte\Engine();
     $parameters = array('subject' => $subject, 'link' => $link, 'baseUri' => $this->urlScript->getHostUrl(), 'host' => $this->urlScript->getHost());
     $email = new Message();
     $email->setFrom($from)->addTo($to)->setSubject($subject)->setHtmlBody($latte->renderToString($this->appDir . '/presenters/templates/emails/registration.latte', $parameters));
     $this->mailer->send($email);
 }