PHP code example of comhon-project / template-renderer
1. Go to this page and download the library: Download comhon-project/template-renderer 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/ */
comhon-project / template-renderer example snippets
use Comhon\TemplateRenderer\TemplateManager;
// the instantiation mechanism should be implemented in a specific place
// and called only one time (TemplateManager should be used as singleton)
$templateManager = new TemplateManager($app);
$rendered = $templateManager->render(
'Hello {{ user.name }} !!!',
['user' => ['name' => 'john doe']]
);
echo $rendered;
// output: Hello john doe !!!
use Comhon\TemplateRenderer\Renderers\RendererInterface;
class MyTemplateRenderer implements RendererInterface
{
public function setDefaultLocale(string $locale) {}
public function setDefaultTimezone(string $timezone) {}
public function validate(string $template) {}
public function render(
string $template,
array $replacements,
string $defaultLocale = null,
string $defaultTimezone = null,
string $preferredTimezone = null
): string {}
}
Template::extend('my-renderer', function ($app) {
return new MyTemplateRenderer($app);
});