Written by Jason den Dulk
A simple, yet powerful template engine.
-
Uses PHP itself as the template engine, so no need to reinvent the wheel or use bloated parsers and interpreters, or learn yet another language.
-
You can create custom component classes that allow you to have extra component specific business logic that can be kept out of the template, or handle boilerplate you dont want to have repeated in every template file.
-
Specify the template either as a string or a file.
-
Direct output. Displays content directly to output for faster rendering. Output to a string (via
__toString
) is also supported. -
Hierarchical. Components can be added to other Components to create output of arbitrary complexity. No need for partials, layouts or helpers as
Component
can be used for all of these roles.
PHP v5.4.0 or greater.
composer require jaypha/j-plate
__construct($template, $initialData)
Constructor for the Component
class.
$template
- The template file to use.
$initialData
- Associative array for values to be used. May be non-associative
if no template is provided.
void setTemplate(string $template = null)
Sets the template file
void setVars(array $values)
Sets all the values.
void set(string $name, mixed $value)
Sets a single value
void remove(string $name)
Removes a value stored under $name.
void add(mixed $value)
Adds a value without a name. Useful when no template is being used.
void clear()
Removes all values.
void display()
Outputs the contents to the output context.
string __toString()
Returns the contents as a string.
A trait that allows the template to be provided directly instead of via a file.
Behaves the same as Component
except that the template is provided directly
instead of via a file.
This project make use of PHP's ability to embed PHP code inside a text
file. Simply surround your code with <?php
and ?>
, or <?=
and ?>
.
All values are loaded into the context and can be accessed directly. For
example, a value set with the name viewName
, can be printed with
<?=$viewName?>
.
Copyright (C) 2017 Jaypha.
Distributed under the Boost Software License, Version 1.0.
See http://www.boost.org/LICENSE_1_0.txt