activecollab/templateengine

抽象模板引擎并提供易于使用的PHP模板引擎的组件

3.0.0 2024-01-23 14:17 UTC

This package is auto-updated.

Last update: 2024-09-23 15:36:00 UTC


README

Build Status

此包提供了一个与多个模板引擎交互的单个接口。它内置了简单的PHP模板引擎

$template_engine = new PhpTemplateEngine('/path/to/templates/dir');

// Set attributes that will be passed to all templates. Method chaining is supported.
$template_engine->setAttributes([
    'app_name' => 'My Awesome App',
    'app_version' => '1.0.0',
])->addAttribute('app_env', 'staging');

// Render template to output buffer
$template_engine->display('/mail/hello.php', ['first_name' => 'John'])

// Render template and return output as a string
$output = $template_engine->fetch('/mail/hello.php', ['first_name' => 'John'])

模板沙盒

模板是沙盒化的,只能放在在构建引擎时指定的模板目录中。如果您尝试使用不在该目录中的模板,模板引擎将抛出 \RuntimeException

$template_engine->fetch('/example/../../../../etc/passwd'); // Will throw an exception