1. Go to this page and download the library: Download esi/simple_tpl library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
esi / simple_tpl example snippets
use Esi\SimpleTpl\Template;
use Esi\SimpleTpl\Storage\FilesystemStorage;
$templateStorage = new FilesystemStorage('./templates/');
$template = new Template($templateStorage);
$template->setTplVars([
'title' => 'Hello, World!',
'content' => 'This is a simple template engine.'
]);
echo $template->parse('example_template');
use Esi\SimpleTpl\Template;
use Esi\SimpleTpl\Storage\DatabaseStorage;
use Esi\SimpleTpl\Storage\DatabaseStorageConfig;
use PDO;
$pdo = new PDO('mysql:host=localhost;dbname=templates', 'user', 'password');
$storageConfig = new DatabaseStorageConfig(); // with the example table structure above, the config defaults to 'templates', 'name', 'content'
$templateStorage = new DatabaseTemplateStorage($pdo, $storageConfig);
$template = new Template($templateStorage);
$template->setTplVars([
'title' => 'Hello, World!',
'content' => 'This is a simple template engine.'
]);
echo $template->parse('example_template');
use Esi\SimpleTpl\Template;
use Esi\SimpleTpl\Storage\FilesystemStorage;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
$templateStorage = new FilesystemStorage('/path/to/templates');
$template = new Template(
$templateStorage,
/**
* Symfony's AbstractAdapter::createSystemCache() returns the best possible adapter that your runtime supports.
* Generally, it will create a cache via PHP files (Opcache must be enabled via opcache.enable in php.ini), and chain that with APCu if your system supports it.
*
* For more information on symfony/cache's available cache pool (PSR-6) adapters:
* @see https://symfony.com/doc/current/components/cache/cache_pools.html
*/
AbstractAdapter::createSystemCache(namespace: 'simple_tpl', defaultLifetime: 300, version: '', directory: sys_get_temp_dir())
);
// ... assign vars, parse /display template, etc ...
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.