Skip to content
docsv0.1.0

LatteTemplateRenderer

Dependency-free {@see TemplateRendererInterface}: a small self-contained subset of Latte syntax (`{layout}`, `{block}`/`{/block}`, `{include}`, `{foreach}`, `{$var}` with auto-escaping and an explicit `|noescape` opt-out) implemented over `preg_replace_callback()`, not the real Latte engine — enough to render this package's shipped templates without pulling in a Composer dependency on `latte/latte`. Every resolved template path is checked against {@see $viewPath} to prevent path traversal outside the configured view root.

LatteTemplateRenderer::__construct()

public function __construct(?string $viewPath = null):

Parameters

Parameters of __construct()
NameTypeDescription
$viewPath?string

LatteTemplateRenderer::setViewPath()

public function setViewPath(string $path): void

Sets the root directory templates are resolved (and traversal-checked) against. Throws `InvalidArgumentException` if `$path` does not exist.

Parameters

Parameters of setViewPath()
NameTypeDescription
$pathstring

LatteTemplateRenderer::render()

public function render(string $template, array $params = []): string

Renders `$template` (a path relative to {@see $viewPath}, or a `{layout}`-linked template it references) with `$params` available as `{$key}` / `{$key.nested}` placeholders.

Parameters

Parameters of render()
NameTypeDescription
$templatestring
$paramsarray