Blade Renderer
is a simple wrapper around illuminate/view
, the package that powers the Blade
templating engine used with Laravel
.
This package allows Blade's powerful and expressive syntax to be uesd in any PHP project without needing to install the full Laravel framework. It abstracts the setup and configuration needed to render blade templates, making it more accessible and straightforward for use in non-Laravel projects.
It uses a similar directory structure as Laravel for organizing views
and caches
.
The views are stored at the resources/views
directory and the view caches at storage/framework/views
.
Blade Renderer
can be used in either of the following two ways.
You can use Blade Renderer to quickly start a new standalone project. To do this, follow these steps:
-
Create a New Project
Run the following command in your terminal to create a new project.
composer create-project abitofmaya/blade-renderer <project-name>
-
Run the Development Server
Navigate into the project directory and start a PHP development server by running:
php -S localhost:8000 -t public
-
Edit
src/app.php
with the following contents:<?php use abitofmaya\BladeRenderer\BladeRenderer; $renderer = new BladeRenderer(); $posts = [ [ 'title' => 'The Art of Minimalism: Living with Less', 'description' => 'Learn how to declutter your life and find happiness in simplicity.' ], [ 'title' => 'The Future of Technology', 'description' => 'Dive into the technological advancements shaping the future.' ] ]; echo $renderer->view(view: 'bladeRenderer', data: ['posts' => $posts]);
-
Create
bladeRenderer.blade.php
inresources/views
directory with the following contents.<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Blade Renderer</title> </head> <body> @foreach($posts as $post) <div> <p><strong>Title</strong>: {{ $post['title'] }}</p> <p><strong>Description</strong>: {{ $post['description'] }}</p> </div> @endforeach </body> </html>
If you have an existing PHP project and want to add Blade templating capabilities, you can include Blade Renderer as a project dependency. Here's how:
-
Install the Package
Run the following command in your terminal to install Blade Renderer.
composer require abitofmaya/blade-renderer
-
Setup Directory Structure
After installation, you will need to manually set up the directory structure for the views and caches. Create the following directories:
resources/views
for storing your Blade templates.storage/framework/views
for storing view caches.