roy404 / blades
A PHP library that provides Blade-like templating functionality, enabling seamless integration of Blade syntax and components.
Requires
- php: ^8.0
- dev-main
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2025-06-07 01:41:49 UTC
README
This library allows you to integrate Blade-like templating functionality into your PHP application. It enables the use of Blade syntax and components, offering a familiar and powerful templating engine for your project.
Installation
To get started, install the bundle via Composer:
composer require roy404/blades
Blades Feature Documentation
Blades
is a PHP library designed to provide Blade-inspired templating capabilities. With this library, you can use Blade syntax and custom directives in your PHP applications, facilitating a smooth transition for developers. The library enhances your templating workflow with custom methods and functionalities that mimic Blade's behavior while offering additional flexibility for use outside the Laravel ecosystem.
Blade Custom Methods Usage Guide
This guide helps you understand when and how to use the compile
, loadDirectives
, and load
methods in your project.
π§© 1. loadDirectives()
π What It Does
- Loads all directive definition files from a given directory.
- Each directive file should define logic extending the compiler.
β When To Use
- You need to register your own custom directives.
- You want to make sure directives are available before calling
compile()
.
Note: You usually donβt need to call this manually β compile() will automatically invoke it if no directives are loaded.
π§ͺ Example
Blade::loadDirectives(__DIR__ . '/directives');
π§© 2. compile()
π What It Does
- Compiles raw template content (as a string).
- Applies all registered compiler instances and directives.
- Returns the final compiled output as a string.
β When To Use
- You want to render template content stored in a variable or database.
- You need to manually post-process or store the compiled output.
π§ͺ Example
$content = '<div>Hello, {{ $name }}!</div>'; echo Blade::compile($content, ['name' => 'Robroy Canales']);
π§© 3. load()
π What It Does
- Loads and compiles a
.php
(or template) file. - Renders it directly with the provided variables.
β When To Use
- You have a physical file you want to render.
- You want to output the view directly (e.g. from a controller or route handler).
π§ͺ Example
Blade::load(__DIR__ . '/views/profile.php', ['user' => $user]);
π οΈ 4. build()
π What It Does
- Initializes a new Blade engine instance using a custom compiler (implementing
ViewsInterface
). - Returns the instance for chaining, such as registering custom directives.
β When To Use
- You want to register custom directives to extend the template engine.
- You are implementing your own logic inside a compiler class (like a plugin).
π§ͺ Example
Blade::build(new Loops)->register(function (Blade $blade) { // Add @break directive $blade->directive('break', fn() => '<?php break; ?>'); // Add @continue directive $blade->directive('continue', fn() => '<?php continue; ?>'); });