Ejemplo n.º 1
0
 /**
  * @param string $view
  * @param string $templateName
  * @param array $params
  * @return string
  * @throws ResourceNotFoundException
  */
 protected function getHtml(string $view, string $templateName, array $params) : string
 {
     $template = null;
     if ($this->templating->exists($templateName)) {
         $template = $templateName;
     }
     if ($template === null) {
         $templateDir = $templateName . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     $viewPath = $view;
     if ($template === null && $viewPath !== '') {
         $templateDir = $viewPath . $templateName . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         $templateDir = static::$TEMPLATE_DIR . $templateName . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         throw new ResourceNotFoundException('View for ' . $templateName . ' does not exist!');
     }
     return $this->templating->render($template, $params);
 }
Ejemplo n.º 2
0
 public function setRequestLayout(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     // Get the necessary informations to check them in layout configurations
     $path = $request->getPathInfo();
     $host = $request->getHost();
     $layouts = $this->config['layouts'];
     // As a layout must be set, we force it to be empty if no layout is properly configured.
     // Then this will throw an exception, and the user will be warned of the "no-layout" config problem.
     $finalLayout = null;
     foreach ($layouts as $layoutConfig) {
         $match = false;
         if ($layoutConfig['host'] && $host === $layoutConfig['host']) {
             $match = true;
         }
         if ($layoutConfig['pattern'] && preg_match('~' . $layoutConfig['pattern'] . '~', $path)) {
             $match = true;
         }
         if ($match) {
             $finalLayout = $layoutConfig;
             break;
         }
     }
     if (null === $finalLayout || !$this->templating->exists($finalLayout['resource'])) {
         throw new \Twig_Error_Loader(sprintf('Unable to find template %s for layout %s. The "layout" parameter must be a valid twig view to be used as a layout.', $finalLayout['resource'], $finalLayout['name']), 0, $finalLayout['resource']);
     }
     $event->getRequest()->attributes->set('_orbitale_cms_layout', $finalLayout);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function renderView(string $view, array $params = []) : string
 {
     $template = null;
     if ($this->templating->exists($this->getTemplateName())) {
         $template = $this->getTemplateName();
     }
     $viewPath = $view;
     if ($template === null && $viewPath) {
         $templateDir = $viewPath . $this->getTemplateName() . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         $templateDir = self::TEMPLATE_DIR . $this->getTemplateName() . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         throw new ResourceNotFoundException('Vardius\\Bundle\\ListBundle\\View\\Renderer: Wrong template path');
     }
     return $this->templating->render($template, $params);
 }