https://github.com/activecollab/templateengine
https://github.com/activecollab/templateengine
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/activecollab/templateengine
- Owner: activecollab
- License: mit
- Created: 2016-05-22T10:59:47.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-01-23T14:18:37.000Z (over 2 years ago)
- Last Synced: 2025-03-30T13:03:29.288Z (about 1 year ago)
- Language: PHP
- Size: 43 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Template Engine
[](https://travis-ci.org/activecollab/templateengine)
This package offers a single interface for interaction with multiple template engines. It ships with simple PHP template engine built in:
```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'])
```
## Template Sandboxing
Templates are sandboxed, and can be placed only in templates directory that is specified when engine is constructed. If you try to use a template that is not in this directory, template engine will throw a `\RuntimeException`:
```php
$template_engine->fetch('/example/../../../../etc/passwd'); // Will throw an exception
```