almhdy / render-ease
A lightweight PHP templating engine with component system and caching - Alpha Release
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-09-22 21:38:22 UTC
README
RenderEase is a lightweight, high-performance PHP templating engine designed for simplicity and efficiency. It features a component-based architecture, file caching, and advanced control structures with a clean, intuitive syntax.
โจ Features
- ๐ Blazing Fast: 56x performance improvement with caching enabled
- ๐งฉ Component System: Reusable components with
{{ include }}
syntax - ๐พ Smart Caching: File-based caching with automatic invalidation
- ๐ก๏ธ Secure: Automatic HTML escaping and XSS protection
- ๐ฆ Lightweight: No dependencies, minimal footprint
- ๐ฏ Simple Syntax: Clean
{{ variable }}
and{{ if condition }}
syntax - ๐ง Extensible: PSR-4 architecture with proper interfaces
๐ฆ Installation
Via Composer:
composer require almhdy/render-ease
Manual Installation:
git clone https://github.com/almhdy24/render-ease.git
cd render-ease
composer install
๐ Quick Start
Basic Usage:
<?php require_once 'vendor/autoload.php'; use Almhdy\RenderEase\RenderEase; $renderer = new RenderEase(); $renderer->set('title', 'Welcome Page'); $renderer->set('username', 'John Doe'); echo $renderer->render('welcome');
With Caching:
$renderer->setCacheDirectory(__DIR__ . '/cache'); $renderer->enableCaching(true); $renderer->setCacheTime(3600); // 1 hour cache // First render: 18ms (compiles + caches) // Subsequent renders: 0.3ms (56x faster! โก) echo $renderer->render('welcome');
๐ Syntax Guide
Variables:
<h1>Welcome, {{ username }}!</h1> <p> Your email: {{ email }} </p>
Conditionals:
{{ if items }} <h2>You have items!</h2> {{ end }} {{ if user.is_admin }} <a href="/admin">Admin Panel</a> {{ end }}
Loops:
{{ for product in products }} <div class="product"> <h3>{{ product.name }}</h3> <p> ${{ product.price }} </p> </div> {{ end }}
Components:
<!-- Include simple component --> {{ include header }} <!-- Include with variables --> {{ include footer with {year: 2024, show_date: true} }} <!-- Conditional components --> {{ if user.logged_in }} {{ include user_dashboard with {user: user} }} {{ else }} {{ include login_form }} {{ end }}
๐งฉ Component System
Create reusable components:
views/header.ease:
<header class="header"> <h1>{{ site_name }}</h1> <nav> <a href="/">Home</a> <a href="/about">About</a> <a href="/contact">Contact</a> </nav> </header>
views/footer.ease:
<footer class="footer"> <p> © {{ year }} {{ site_name }}. All rights reserved. </p> {{ if show_date }} <p> Page rendered at: {{ current_date }} </p> {{ end }} </footer>
views/welcome.ease:
<!DOCTYPE html> <html> <head> <title>{{ title }}</title> <style> {{ include styles }} </style> </head> <body> {{ include header }} <main class="content"> <h1>Welcome, {{ username }}!</h1> <p> {{ message }} </p> {{ if products }} <div class="products"> {{ for product in products }} <div class="product"> {{ product.name }} - ${{ product.price }} </div> {{ end }} </div> {{ end }} </main> {{ include footer with {year: 2024, show_date: true} }} </body> </html>
โก Performance & Caching
Enable Caching:
$renderer->setCacheDirectory(__DIR__ . '/cache'); $renderer->enableCaching(true); $renderer->setCacheTime(3600); // 1 hour expiration
Performance Metrics:
ยท First Render: ~18ms (parse + compile + cache) ยท Cached Render: ~0.3ms (read from cache) ยท Improvement: 56x faster โก
Clear Cache:
// Clear all cached templates $renderer->clearCache();
๐ก๏ธ Security Features
Automatic HTML Escaping:
<!-- User input is automatically escaped --> <p> {{ user_generated_content }} </p> <!-- becomes --> <p> <?php echo htmlspecialchars($user_generated_content, ENT_QUOTES, 'UTF-8'); ?> </p>
Raw Output (when needed):
<!-- Use carefully for trusted HTML content --> <div> {{ raw html_content }} </div>
๐ API Reference
Core Methods:
// Set variables $renderer->set('key', 'value'); $renderer->setMultiple(['key1' => 'value1', 'key2' => 'value2']); // Render templates $output = $renderer->render('template-name'); // Include components $output = $renderer->include('component-name', ['var' => 'value']); // Cache management $renderer->enableCaching(true); $renderer->setCacheDirectory('/path/to/cache'); $renderer->setCacheTime(3600); $renderer->clearCache(); // Configuration $renderer->setTemplateDirectory('/custom/views/path'); $renderer->setExtension('html'); // Change from .ease to .html $renderer->setErrorTemplate('custom-error');
๐ฏ Advanced Usage
Custom Template Directory:
$renderer->setTemplateDirectory(__DIR__ . '/custom-views');
Different File Extension:
$renderer->setExtension('html'); // Use .html instead of .ease
Error Handling:
try { echo $renderer->render('template'); } catch (Almhdy\RenderEase\Exceptions\TemplateNotFoundException $e) { echo "Template not found: " . $e->getMessage(); } catch (Exception $e) { echo "Error: " . $e->getMessage(); }
๐ Project Structure
render-ease/
โโโ src/
โ โโโ Contracts/
โ โ โโโ TemplateRendererInterface.php
โ โโโ Exceptions/
โ โ โโโ TemplateNotFoundException.php
โ โโโ Cache/
โ โ โโโ CacheManager.php
โ โโโ Parsers/
โ โ โโโ ParserInterface.php
โ โ โโโ ShortHandParser.php
โ โ โโโ VariableParser.php
โ โโโ RenderEase.php
โ โโโ RenderEaseFacade.php
โโโ views/
โ โโโ welcome.ease
โ โโโ header.ease
โ โโโ footer.ease
โ โโโ error.ease
โ โโโ simple.ease
โโโ Examples/
โ โโโ index.php
โโโ composer.json
โโโ LICENSE
โโโ README.md
๐ค Contributing
We welcome contributions! Please feel free to submit pull requests, open issues, or suggest new features.
- Fork the repository
- Create your feature branch (git checkout -b feature/AmazingFeature)
- Commit your changes (git commit -m 'Add some AmazingFeature')
- Push to the branch (git push origin feature/AmazingFeature)
- Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Benchmarks
Operation Time Improvement First Render ~18ms - Cached Render ~0.3ms 56x faster โก Memory Usage < 5MB Minimal footprint Components 0.1ms each Highly efficient
๐ก Why Choose RenderEase?
ยท Simplicity: Clean syntax that's easy to learn and use ยท Performance: 56x faster with caching enabled ยท Security: Built-in HTML escaping and XSS protection ยท Flexibility: Component system for reusable code ยท Lightweight: No dependencies, minimal overhead ยท Professional: PSR-4 architecture, proper interfaces
๐ Support
If you have any questions or need help, please:
- Check the Examples directory
- Open an Issue
- Email: almhdybdallh24@gmail.com
RenderEase - Making PHP templating simple, fast, and secure! ๐
โ ๏ธ Alpha Release: This is v0.0.1-alpha - APIs may change, and there may be undiscovered issues. Not recommended for production use yet.