PHP code example of echo-fusion / templatemanager
1. Go to this page and download the library: Download echo-fusion/templatemanager 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/ */
echo-fusion / templatemanager example snippets
use EchoFusion\TemplateManager\TemplateManager;
$templates = TemplateManager::fromConfig([
'paths' => [__DIR__ . '/templates'],
'globals' => ['appName' => 'My app'],
]);
echo $templates->render('home', ['user' => ['name' => 'Ann']]); // templates/home.tpl
use EchoFusion\TemplateManager\Engines\SimpleEngine;
$engine = new SimpleEngine($templates->getFinder(), 'tpl');
$engine->addFilter('money', fn (float $v, string $cur = '$') => $cur . number_format($v, 2));
$templates->addEngine('tpl', $engine);
$this->layout('layouts/main', ['title' => 'Home'])
$templates->addPath(__DIR__ . '/modules/blog/templates', 'blog');
$templates->render('@blog/posts/index');
foreach ($modules->getTemplatePaths() as $name => $path) {
$templates->addPath($path, $name);
}
return [
'paths' => [
__DIR__ . '/templates', // no key: default namespace
'blog' => __DIR__ . '/modules/blog/views', // string key: namespace
],
'globals' => ['appName' => 'My app'],
'engines' => [ // order matters: first engine that has the template wins
'tpl' => ['options' => ['cache' => __DIR__ . '/storage/templates', 'auto_reload' => false]],
'php' => [],
'twig' => ['options' => ['cache' => __DIR__ . '/storage/twig']], // needs twig/twig
'blade' => ['class' => MyBladeEngine::class, 'options' => []], // any engine class
],
];
bash
composer