A simple template engine for simple PHP applications.
- Composer
- PHP 7.4+
composer require par274/templater
OR
git clone https://github.com/par274/simple-templater
composer update
<?php
use Templater\Templater;
?>
<?php echo $this->getDoctype(); ?>
<?php
$templater->addGlobals([
'test' => [
'status' => 'ok'
]
]);
?>
<?php echo $test->status; ?>
<?php $this->setPageTitle('Depremler Tablo'); ?>
<?php
$data = [
'test' => 'test'
];
echo $templater->render('{page_container:index}', $data);
?>
View/view.index.php
<?php echo $test; ?>
This is the function where you can easily define such as style and js definitions.
<head>
<?php
echo $this->setHead([
'title' => [
'content' => $this->getPageTitle()
],
'{meta_0}' => [
'attributes' => [
'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=utf-8'
]
],
'{meta_1}' => [
'attributes' => [
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=Edge'
]
],
'{meta_2}' => [
'attributes' => [
'name' => 'viewport',
'content' => 'user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1'
]
],
'{link_0}' => [
'attributes' => [
'rel' => 'stylesheet',
'href' => "public/vendor/vendor.css?v=1673363766"
]
],
'{link_1}' => [
'attributes' => [
'rel' => 'stylesheet',
'href' => "public/style.css?v=" . time()
]
]
]);
?>
</head>
<?php
define('APPLICATION_SELF', __DIR__);
require(APPLICATION_SELF . '/vendor/autoload.php');
use Templater\Templater;
$templater = new Templater();
$templater->setPath(APPLICATION_SELF . '/View');
$templater->addGlobals([
'test' => [
'status' => 'ok'
]
]);
$data = [];
echo $templater->render('{page_container:index}', $data);
?>
The license of this library is MIT(MIT License). It cannot be sold, but you can use it.
You can check this file for more information.