Ejemplo n.º 1
0
 /**
  * Resolve a template pathname from its name and type.
  *
  * @param string $name Name of the template.
  * @param string $prefix Template prefix.
  * @param array $tried Reference to an array where tried paths are collected.
  *
  * @return string|false
  */
 protected function resolve_template($name, $prefix, &$tried = [])
 {
     $tried = $tried ?: [];
     if ($prefix) {
         $name = TemplateName::from($name)->with_prefix($prefix);
     }
     try {
         return $this->renderer->resolve_template($name);
     } catch (TemplateNotFound $e) {
         $tried = $e->tried;
         return null;
     }
 }
Ejemplo n.º 2
0
 protected function resolve_template($name)
 {
     $template_resolver = $this->template_resolver;
     $file = $this->get_file();
     if ($file) {
         // FIXME-20150721: use a decorator
         $template_resolver = clone $this->template_resolver;
         $basic_template_resolver = null;
         if ($template_resolver instanceof Render\BasicTemplateResolver) {
             $basic_template_resolver = $template_resolver;
         } else {
             if ($template_resolver instanceof Render\TemplateResolverDecorator) {
                 $basic_template_resolver = $template_resolver->find_renderer(Render\BasicTemplateResolver::class);
             }
         }
         if ($basic_template_resolver) {
             $basic_template_resolver->add_path(dirname($file));
         }
     }
     $tries = [];
     $template_pathname = $template_resolver->resolve($name, ['.patron', '.html'], $tries);
     if ($template_pathname) {
         return $this->create_template_from_file($template_pathname);
     }
     $template_name = TemplateName::from($name);
     $template_pathname = $template_resolver->resolve($template_name->as_partial, ['.patron', '.html'], $tries);
     if ($template_pathname) {
         return $this->create_template_from_file($template_pathname);
     }
     throw new TemplateNotFound("Template not found: {$name}.", $tries);
 }
Ejemplo n.º 3
0
 /**
  * Decorates a content with a template.
  *
  * <pre>
  * <p:decorate
  *     with = string>
  *     <!-- Content: p:with-param*, template -->
  * </p:decorate>
  * </pre>
  *
  * The content of the markup is rendered to create the component to decorate, it is then passed
  * to the decorating template as the `component` variable.
  *
  * The name of the decorating template is specified with the `with` attribute, and is
  * interpolated e.g. if "page" is specified the template name "@page" is used; if "admin/page"
  * is specified the template name "admin/@page" is used.
  *
  * The parameters specified using `with-param` are all turned into variables.
  *
  * Example:
  *
  * <pre>
  * <p:decorate with="page">
  *     <p:page:content id="body" />
  * </p:decorate>
  * </pre>
  *
  * @param array $args
  * @param Engine $engine
  * @param mixed $template
  *
  * @return string
  */
 public static function markup_decorate(array $args, Engine $engine, $template)
 {
     $template_name = $args['with'];
     $rendered_template = $engine($template);
     unset($args['with']);
     $engine->context['component'] = $rendered_template;
     foreach ($args as $name => $value) {
         $engine->context[$name] = $value;
     }
     return $engine->callTemplate(TemplateName::from($template_name)->as_layout, $args);
 }