1. Go to this page and download the library: Download knifelemon/comment-template 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/ */
knifelemon / comment-template example snippets
KnifeLemon\CommentTemplate\Engine;
// Initialize template engine
$template = new Engine();
$template->setPublicPath(__DIR__); // Root directory (where index.php is)
$template->setSkinPath('templates'); // Relative to public path
$template->setAssetPath('assets'); // Relative to public path
$template->setFileExtension('.php');
$template->setCacheBusting(true); // Append ?timestamp to asset URLs
// Render template
$template->render('homepage', [
'title' => 'Welcome',
'content' => 'Hello World!'
]);
KnifeLemon\CommentTemplate\Engine;
$app = Flight::app();
$app->register('view', Engine::class, [], function (Engine $engine) {
$engine->setPublicPath(__DIR__); // Root directory (where index.php is)
$engine->setSkinPath('views'); // Relative to public path
$engine->setAssetPath('assets'); // Relative to public path
$engine->setFileExtension('.php');
$engine->setCacheBusting(true); // Enable cache busting
});
$app->map('render', function(string $template, array $data) use ($app): void {
echo $app->view()->render($template, $data);
});
KnifeLemon\CommentTemplate\Engine;
$app = Flight::app();
$app->register('view', Engine::class, [
__DIR__, // Public path (root directory where index.php is)
'views', // Templates path (relative to public path)
'assets', // Asset path (relative to public path)
'.php', // File extension
true // Enable cache busting
]);
$app->map('render', function(string $template, array $data) use ($app): void {
echo $app->view()->render($template, $data);
});
// Via constructor (5th parameter)
$template = new Engine(__DIR__, 'views', 'assets', '.php', true);
// Via setter
$template->setCacheBusting(true);
// Example: if your index.php is at /var/www/html/myapp/index.php
$template->setPublicPath('/var/www/html/myapp'); // Root directory
// Windows example: if your index.php is at C:\xampp\htdocs\myapp\index.php
$template->setPublicPath('C:\\xampp\\htdocs\\myapp');
use KnifeLemon\CommentTemplate\Engine;
use Tracy\Debugger;
// Enable Tracy (must be called before any output)
Debugger::enable(Debugger::DEVELOPMENT);
// Use CommentTemplate as normal - logging happens automatically
$template = new Engine();
$template->setPublicPath(__DIR__);
$template->setSkinPath('templates');
$template->setAssetPath('assets');
$template->render('homepage', ['title' => 'Hello World']);
html
<!--@layout(layout)-->
<h1>{$title}</h1>
<p>{$content}</p>
html
<!-- Inline small images as data URIs for faster loading -->
<img src="<!--@base64(images/logo.png)-->" alt="Logo">
<div style="background-image: url('<!--@base64(icons/star.svg)-->');">
Small icon as background
</div>
html
<!-- Execute PHP functions and constants -->
<div>Current time: <!--@echo(date('Y-m-d H:i:s'))--></div>
<div>PHP Version: <!--@echo(PHP_VERSION)--></div>
<div>App Version: <!--@echo(APP_VERSION)--></div>