-
Notifications
You must be signed in to change notification settings - Fork 4
Template
Rougin Gutib edited this page Dec 22, 2023
·
9 revisions
The Template
is an optional component for Slytherin in handling HTML-like views. Although PHP as the programming language is a template engine, having an abstract for the said template engine can add additional features such as separating concerns between the data and its corresponding view template.
Slytherin provided its own Template
component. The said component is implemented by the Rougin\Slytherin\Template\RendererInterface
:
namespace Rougin\Slytherin\Template;
interface RendererInterface
{
/**
* Renders a template.
*
* @param string $template
* @param array<string, mixed> $data
* @return string
*/
public function render($template, array $data = array());
}
// /views/hello.php
Hello world!
// app/web/index.php
use Rougin\Slytherin\Template\Renderer;
// Set the location of the template views ---
$path = __DIR__ . '/views';
// ------------------------------------------
$renderer = new Renderer($path);
echo $renderer->render('hello');
The example code above should return Hello world!
after executing the said code in a terminal:
$ php app/web/index.php
Hello world!