Пример #1
0
 /**
  * Determine if the renderer can load the requested template.
  *
  * @param ViewEvent $e
  * @return bool|TwigRenderer
  */
 public function selectRenderer(ViewEvent $e)
 {
     if ($this->renderer->canRender($e->getModel()->getTemplate())) {
         return $this->renderer;
     }
     return false;
 }
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return TwigRenderer
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var \ZfcTwig\moduleOptions $options */
     $options = $serviceLocator->get('ZfcTwig\\ModuleOptions');
     $renderer = new TwigRenderer($serviceLocator->get('Zend\\View\\View'), $serviceLocator->get('Twig_Loader_Chain'), $serviceLocator->get('Twig_Environment'), $serviceLocator->get('ZfcTwig\\View\\TwigResolver'));
     $renderer->setCanRenderTrees($options->getDisableZfmodel());
     $renderer->setHelperPluginManager($serviceLocator->get('ZfcTwigViewHelperManager'));
     return $renderer;
 }
Пример #3
0
 public function render($template = null, $leftWidth = 2, $force = false)
 {
     $template = $template ? 'discussion/helper/' . $template . '/' . $template : $this->getOption('template');
     if ($force || !$this->request->isXmlHttpRequest()) {
         return $this->renderer->render($template, ['discussions' => $this->discussions, 'isArchived' => $this->archived, 'object' => $this->getObject(), 'forum' => $this->getForum(), 'leftWidth' => $leftWidth]);
     } else {
         return '';
     }
 }
Пример #4
0
 /**
  * Produce a preview of the mailing content.
  *
  * @return null|string
  */
 public function generatePreview()
 {
     $this->updateTemplateVarsWithContact($this->getContactService()->getContact());
     if (is_null($this->mailing)) {
         throw new \RuntimeException("The mailing object is empty. Did set the template");
     }
     try {
         return $this->renderer->render($this->mailing->getTemplate()->getTemplate(), array_merge_recursive(['content' => $this->personaliseMessage($this->email->getMessage())], $this->templateVars));
     } catch (\Twig_Error_Syntax $e) {
         print sprintf("Something went wrong. Error message: %s", $e->getMessage());
     }
     return true;
 }
Пример #5
0
 public function render($limit = 25)
 {
     $user = $this->userManager->getUserFromAuthenticator();
     $key = hash('sha256', serialize($user));
     $output = '';
     if ($this->storage->hasItem($key)) {
         //return $this->storage->getItem($key);
     }
     if ($user) {
         $notifications = $this->notificationManager->findNotificationsBySubscriber($user, $limit);
         $output = $this->renderer->render($this->template, ['notifications' => $notifications]);
         $this->storage->setItem($key, $output);
     }
     return $output;
 }
Пример #6
0
 /**
  * {@inheritDoc}
  */
 public function __invoke($name = null, $values = null)
 {
     if (0 == func_num_args()) {
         return $this;
     }
     // If we were passed only a view model, just render it.
     if ($name instanceof ModelInterface) {
         return $this->getView()->render($name);
     }
     if (is_scalar($values)) {
         $values = array();
     } elseif ($values instanceof ModelInterface) {
         $values = $values->getVariables();
     } elseif (is_object($values)) {
         if (null !== ($objectKey = $this->getObjectKey())) {
             $values = array($objectKey => $values);
         } elseif (method_exists($values, 'toArray')) {
             $values = $values->toArray();
         } else {
             $values = get_object_vars($values);
         }
     }
     return $this->twigRenderer->render($name, $values);
 }