alizharb / azhbx
A modern, production-ready PHP 8.5+ templating engine inspired by Handlebars.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/alizharb/azhbx
Requires
- php: >=8.3
- symfony/console: ^7.3
- symfony/var-dumper: ^7.0
Requires (Dev)
- eftec/bladeone: ^4.19
- friendsofphp/php-cs-fixer: ^3.90
- illuminate/support: ^12.39
- illuminate/view: ^12.39
- pestphp/pest: ^3.0
- phpstan/phpstan: ^2.1
- smarty/smarty: ^5.7
- symfony/framework-bundle: ^7.3
- symfony/http-kernel: ^7.3
- twig/twig: ^3.22
README
๐ AzHbx
Next-Generation PHP Templating Engine
Handlebars-inspired โข Modern PHP โข Production-Ready
Features โข Installation โข Quick Start โข Documentation โข Examples
๐ฏ Overview
AzHbx (AlizHarb Handlebars Extended)
is a powerful, modern PHP templating engine designed for PHP 8.3+. It combines the elegance of Handlebars syntax with cutting-edge PHP features like Property Hooks and Attributes, delivering exceptional performance and developer experience.
Why AzHbx?
- ๐ Secure by Default: Auto-escaping prevents XSS attacks
- โก Blazing Fast: Compiles to native PHP with OpCache support
- ๐จ Theme System: Built-in multi-theme support with fallback logic
- ๐งฉ Modular Architecture: Organize templates by feature/package
- ๐ Plugin System: Extend functionality with PHP 8.3+ Attributes
- ๐ฆ Zero Dependencies: Works with or without Composer
- ๐ฏ Developer-Friendly: Clean syntax, comprehensive docs, great DX
โจ Features
Core Templating
- Handlebars-Inspired Syntax: Familiar
{{ }}expressions - Nested Data Access: Dot notation (
{{ user.profile.name }}) - Control Structures:
if,unless,each,with - Layouts & Partials: Template inheritance and reusable components
- Custom Helpers: Extend with your own logic
- Whitespace Control: Fine-tune output formatting
Advanced Features
- ๐จ Theme Management: Switch themes at runtime with smart fallbacks
- ๐ฆ Module System: Namespace templates by feature (
blog::post) - ๐ Plugin Architecture: Use PHP 8.3+
#[Helper]attributes - โก Async Support: Compatible with PHP Fibers for non-blocking I/O
- ๐ Security First: XSS prevention with auto-escaping
- ๐พ Smart Caching: Automatic recompilation on file changes
- ๐ Framework Adapters: Native integration for Laravel and Symfony
- ๐๏ธ High Performance: Compile-time optimizations make it faster than Twig and Blade
- ๐ ๏ธ Profiler & Debug Toolbar: Real-time performance stats and hot reload during development.
- โ๏ธ Error Code Catalog: Standardized error codes for consistent error handling.
- ๐ง Quality Tools: Integrated PHPStan and PHP-CS-Fixer for static analysis and code style.
๐ฆ Installation
Via Composer (Recommended)
composer require alizharb/azhbx
Standalone (No Composer)
Download the source and include the autoloader:
require 'path/to/azhbx/src/autoload.php';
๐ Quick Start
use AlizHarb\AzHbx\Engine; // Initialize $engine = new Engine([ 'views_path' => __DIR__ . '/views', 'cache_path' => __DIR__ . '/cache', // Optional: Custom paths for themes and modules // 'themes_path' => __DIR__ . '/custom_themes', // 'modules_path' => __DIR__ . '/custom_modules', ]); // Render echo $engine->render('welcome', [ 'user' => [ 'name' => 'Alice', 'role' => 'Admin' ] ]);
Template (views/themes/default/welcome.hbx):
<h1>Welcome, {{ user.name }}!</h1> <p>Role: {{ user.role }}</p>
๐ Documentation
๐ Online Documentation
Visit the live documentation: https://alizharb.github.io/azhbx/
Browse comprehensive guides and examples:
- Introduction
- Installation & Configuration
- Basic Syntax
- Control Structures
- Layouts & Partials
- Custom Helpers
- Plugins & Extensions
- Themes & Modules
- Advanced Topics
๐ Local Documentation
You can also run the documentation website locally:
php -S localhost:8000 -t docs
Visit http://localhost:8000 to browse the interactive docs.
๐ก Examples
Explore real-world examples in the examples/ directory:
php -S localhost:8001 -t examples
Visit http://localhost:8001 to see:
- Basic rendering
- Control structures
- Layouts and partials
- Custom helpers
- Theme switching
- Module system
- Plugin architecture
- Async rendering with Fibers
๐งฉ Component System
AzHbx supports a powerful component system with Blade-like syntax:
<!-- Inline Component --> <az-Icon name="user" size="lg" /> <!-- Block Component --> <az-Alert type="error"> <strong>Error!</strong> Something went wrong. </az-Alert>
Components are stored in views/components/ (e.g., views/components/alert.hbx).
โก Directives
Directives are special helpers starting with @ for common tasks:
{{ @csrf }}- CSRF token input{{ @method "PUT" }}- HTTP method spoofing{{# @auth }}...{{/ @auth }}- Content for authenticated users{{# @guest }}...{{/ @guest }}- Content for guests{{# @env "production" }}...{{/ @env }}- Environment-specific content
๐ Plugin System
Create powerful extensions using PHP 8.5+ Attributes:
use AlizHarb\AzHbx\Contracts\PluginInterface; use AlizHarb\AzHbx\Attributes\Helper; use AlizHarb\AzHbx\Attributes\Directive; class MyPlugin implements PluginInterface { public function register(Engine $engine): void {} #[Helper('uppercase')] public function uppercase(string $text): string { return strtoupper($text); } #[Directive('myDirective')] public function myDirective(array $context): string { return "Custom Directive"; } }
๐จ Theme System
Switch themes dynamically:
$engine->setTheme('dark'); echo $engine->render('home', $data);
Directory Structure:
views/
โโโ themes/
โ โโโ default/
โ โ โโโ home.hbx
โ โโโ dark/
โ โโโ home.hbx โ Overrides default
โโโ partials/
โโโ header.hbx
๐งช Testing
Run the test suite:
composer test
Or with coverage:
composer test:coverage
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Development Setup
git clone https://github.com/AlizHarb/azhbx.git cd azhbx composer install composer test
๐ Requirements
- PHP: 8.3 or higher
- Extensions:
mbstring
๐ License
AzHbx is open-source software licensed under the MIT License.
๐ Acknowledgments
Inspired by Handlebars.js and modern PHP best practices.
Built with โค๏ธ by Ali Harb
