Example #1
0
 public function getProcessedPlaceholderMarkup($placeholderName, $placeholderContents)
 {
     if (array_key_exists($placeholderName, $this->processedBlockMarkupCache)) {
         return $this->processedBlockMarkupCache[$placeholderName];
     }
     /*
      * Process snippets
      */
     $markup = Snippet::processPageMarkup($this->getFileName() . md5($placeholderName), $this->theme, $placeholderContents);
     /*
      * Inject global view variables
      */
     $globalVars = ViewHelper::getGlobalVars();
     if (!empty($globalVars)) {
         $markup = TextParser::parse($markup, $globalVars);
     }
     return $this->processedBlockMarkupCache[$placeholderName] = $markup;
 }
Example #2
0
 public static function addContentToMailer($message, $code, $data)
 {
     if (isset(self::$cache[$code])) {
         $template = self::$cache[$code];
     } else {
         self::$cache[$code] = $template = self::findOrMakeTemplate($code);
     }
     /*
      * Inject global view variables
      */
     $globalVars = ViewHelper::getGlobalVars();
     if (!empty($globalVars)) {
         $data = (array) $data + $globalVars;
     }
     /*
      * Subject
      */
     $customSubject = $message->getSwiftMessage()->getSubject();
     if (empty($customSubject)) {
         $message->subject(Twig::parse($template->subject, $data));
     }
     /*
      * HTML contents
      */
     $html = Twig::parse($template->content_html, $data);
     if ($template->layout) {
         $html = Twig::parse($template->layout->content_html, ['content' => $html, 'css' => $template->layout->content_css] + (array) $data);
     }
     $message->setBody($html, 'text/html');
     /*
      * Text contents
      */
     if (strlen($template->content_text)) {
         $text = Twig::parse($template->content_text, $data);
         if ($template->layout) {
             $text = Twig::parse($template->layout->content_text, ['content' => $text] + (array) $data);
         }
         $message->addPart($text, 'text/plain');
     }
 }
Example #3
0
 /**
  * Renders a requested content file.
  * The framework uses this method internally.
  * @param string $name The content view to load.
  * @param array $parameters Parameter variables to pass to the view.
  * @return string
  */
 public function renderContent($name, $parameters = [])
 {
     /*
      * Extensibility
      */
     if (($event = $this->fireEvent('page.beforeRenderContent', [$name], true)) || ($event = Event::fire('cms.page.beforeRenderContent', [$this, $name], true))) {
         $content = $event;
     } elseif (($content = Content::loadCached($this->theme, $name)) === null) {
         throw new CmsException(Lang::get('cms::lang.content.not_found_name', ['name' => $name]));
     }
     $fileContent = $content->parsedMarkup;
     /*
      * Inject global view variables
      */
     $globalVars = ViewHelper::getGlobalVars();
     if (!empty($globalVars)) {
         $parameters = (array) $parameters + $globalVars;
     }
     /*
      * Parse basic template variables
      */
     if (!empty($parameters)) {
         $fileContent = TextParser::parse($fileContent, $parameters);
     }
     /*
      * Extensibility
      */
     if (($event = $this->fireEvent('page.renderContent', [$name, $fileContent], true)) || ($event = Event::fire('cms.page.renderContent', [$this, $name, $fileContent], true))) {
         return $event;
     }
     return $fileContent;
 }