TemplateRenderer

Class.

use Saij\WpAppFramework\Twig\TemplateRenderer;

Renders the Twig templates of a framework instance (theme, child theme or plugin).

Template names are paths relative to the src/ directory of each level, including the extension (e.g. Component/Button.twig). Names without a namespace are looked up in the search paths of the instance, then in the framework, so a higher level overrides a template by providing the same path:

  • theme: child theme overrides/{slug}/ → theme src/ → framework,
  • child theme: child theme src/ → framework,
  • plugin: child theme overrides/{slug}/ → theme overrides/{slug}/ → plugin src/ → framework. @theme/… (themes, child themes), @plugin/… (plugins) and @framework/… address exactly one level and cannot be overridden.

Names starting with the template prefix of a plugin declared in extra.wp-app-framework.template-plugins, or in a child theme of its parent theme, call the public template functions and filters of that plugin or theme.

Provided by the framework at runtime; services receive it through their constructor. The Twig environment is created on the first render.

Constants

ConstantValueDescription
TEMPLATE_DIRECTORY'src'Directory of the templates inside each level, relative to its root.
OVERRIDE_DIRECTORY'overrides'Directory of a theme or child theme with overrides of templates of other instances, one subdirectory per slug.

Methods

render()

render(string $name, array $context = []): string

Renders a template.

ParameterTypeDefaultDescription
namestringrequiredE.g. Component/Button.twig or @framework/Component/Button.twig.
contextarray<string, mixed>[]Template variables.

Returns string