Download the PHP package knifelemon/comment-template without Composer
On this page you can find all versions of the php package knifelemon/comment-template. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download knifelemon/comment-template
More information about knifelemon/comment-template
Files in knifelemon/comment-template
Package comment-template
Short Description A PHP template engine with asset compilation, template inheritance, and variable processing
License MIT
Informations about the package comment-template
CommentTemplate
A powerful PHP template engine with asset compilation, template inheritance, and variable processing. CommentTemplate provides a simple yet flexible way to manage templates with built-in CSS/JS minification and caching.
Features
- Template Inheritance: Use layouts and include other templates
- Asset Compilation: Automatic CSS/JS minification and caching
- Variable Processing: Template variables with filters and commands
- Base64 Encoding: Inline assets as data URIs
- Flight Framework Integration: Optional integration with Flight PHP framework
Installation
Install via Composer:
Quick Start
Basic Usage
Flight Framework Integration
Method 1: Using Callback (Recommended)
Method 2: Using Constructor Parameters
Template Directives
Asset Loading Strategies
CommentTemplate supports different JavaScript loading strategies:
- Normal:
<!--@js(file)-->- Standard blocking script load - Async:
<!--@jsAsync(file)-->- Non-blocking, executes immediately when loaded - Defer:
<!--@jsDefer(file)-->- Non-blocking, waits for HTML parsing to complete - Top placement: Use
jsTop*variants to load scripts in the<head>section - Single files: Use
*Single*variants to skip minification and load individual files
Layout Inheritance
Use layouts to create a common structure:
layout.php:
page.php:
Asset Management
CSS Files
JavaScript Files
Wildcard Support:
- Use
*to match multiple files:<!--@css(/css/*.css)--> - Files are processed in alphabetical order for consistent output
- Works with all asset directives:
@css,@js,@jsAsync,@jsDefer, etc.
Priority Ordering:
All asset directives (@css, @cssSingle, @js, @jsAsync, @jsDefer, @jsTop, @jsTopAsync, @jsTopDefer, @jsSingle, @jsSingleAsync, @jsSingleDefer) support optional priority ordering by adding a number after the file path:
Priority rules:
- No priority: Files are loaded in the order they appear in the template
- All prioritized: Sorted by priority number (ascending)
- Mixed: Prioritized files first (sorted by number), then non-prioritized in original order
Cache Busting
Enable cache busting to append a timestamp query string (?{filemtime}) to compiled asset URLs. This forces browsers to reload assets when files are updated.
Output comparison:
Works with all asset types: @css, @cssSingle, @js, @jsAsync, @jsDefer, @jsTop, @jsTopAsync, @jsTopDefer, @jsSingle, @jsSingleAsync, @jsSingleDefer.
Base64 Encoding
Asset Copying
Asset Directives in CSS/JS Files
CommentTemplate also processes asset directives within CSS and JavaScript files during compilation:
CSS Example:
JavaScript Example:
Benefits:
- Asset directives are processed during CSS/JS compilation
- Files are automatically copied to the public directory
- URLs are generated with correct asset paths
- Base64 encoding works in CSS/JS files too
PHP Code Execution
Execute PHP code and output the result using <!--@echo()-->:
In JavaScript files:
In CSS files:
Features:
- Executes any PHP expression (functions, constants, class methods)
- Supports nested parentheses and string literals
- Handles complex expressions like
Flight::getUrl('route') - Works in HTML templates, CSS files, and JavaScript files
- Access template variables when used in template context
- Errors are silently replaced with empty string
Important Notes:
- Template variables (
$data) are available in HTML templates - In CSS/JS files, only global functions, constants, and static methods are accessible
- The code is executed during template compilation
- Use carefully as it executes arbitrary PHP code
Path Configuration
CommentTemplate provides intelligent path handling for both relative and absolute paths:
Public Path
The Public Path is the root directory of your web application, typically where index.php resides. This is the document root that web servers serve files from.
Templates Path Configuration
Templates path supports both relative and absolute paths:
Asset Path Configuration
Asset path also supports both relative and absolute paths:
Smart Path Detection:
- Relative Paths: No leading separators (
/,\) or drive letters - Unix Absolute: Starts with
/(e.g.,/var/www/assets) - Windows Absolute: Starts with drive letter (e.g.,
C:\www,D:/assets) - UNC Paths: Starts with
\\(e.g.,\\server\share)
How it works:
- All paths are automatically resolved based on type (relative vs absolute)
- Relative paths are combined with the public path
@cssand@jscreate minified files in:{resolvedAssetPath}/css/or{resolvedAssetPath}/js/@assetcopies single files to:{resolvedAssetPath}/{relativePath}@assetDircopies directories to:{resolvedAssetPath}/{relativePath}- Smart caching: files only copied when source is newer than destination
Asset Directory Copying Examples
Directory structure example:
Template Includes
Variable Processing
Variable Filters
Variable Commands
Chain Multiple Filters
Example:
Comments
Template comments are completely removed from the output and won't appear in the final HTML:
Note: Template comments {* ... *} are different from HTML comments <!-- ... -->. Template comments are removed during processing and never reach the browser.
API Reference
Engine Class
Constructor
Methods
render(string $template, array $data = []): void
- Render template and output to browser
fetch(string $template, array $data = []): string
- Render template and return as string
setPublicPath(string $path): void
- Set public path for asset compilation
setSkinPath(string $path): void
- Set template directory path (supports both relative and absolute paths)
setFileExtension(string $extension): void
- Set template file extension
setAssetPath(string $path): void
- Set asset storage path (supports both relative and absolute paths)
setCacheBusting(bool $enabled): void
- Enable or disable cache busting (appends
?{filemtime}to asset URLs)
getPublicPath(): string
- Get current public path
getSkinPath(): string
- Get current template directory path
getFileExtension(): string
- Get current template file extension
getAssetPath(): string
- Get current asset storage path
getCacheBusting(): bool
- Get current cache busting setting
This will:
- Minify and combine CSS files
- Minify and combine JS files
- Cache compiled assets
- Inject
<link>and<script>tags automatically
Development
Running Tests
Code Analysis
Test Coverage
Tracy Debugger Integration
CommentTemplate includes integration with Tracy Debugger for development logging and debugging.

Installation
Usage
Debug Panel Features
CommentTemplate adds a custom panel to Tracy's debug bar with four tabs:
- Overview: Configuration, performance metrics, and counts
- Assets: CSS/JS compilation details with compression ratios
- Variables: Original and transformed values with applied filters
- Timeline: Chronological view of all template operations
What Gets Logged
- Template rendering (start/end, duration, layouts, imports)
- Asset compilation (CSS/JS files, sizes, compression ratios)
- Variable processing (original/transformed values, filters)
- Asset operations (base64 encoding, file copying)
- Performance metrics (duration, memory usage)
Note: Zero performance impact when Tracy is not installed or disabled.
See examples/tracy/ and examples/flightphp/ for complete working examples.
License
MIT License. See LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request