almhdy/render-ease

A lightweight PHP templating engine with component system and caching - Alpha Release

0.0.1-alpha 2025-08-22 05:35 UTC

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.

PHP License Version

โœจ 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>
    &copy; {{ 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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:

  1. Check the Examples directory
  2. Open an Issue
  3. 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.