View template engine of PHP extracted from Laravel

Related tags

Laravel blade
Overview

Blade

【简体中文】

This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

Installation

With Composer, you just need to run

composer require xiaoler/blade

If you haven't use composer, you should add all the files in folder src to your project folder, and then require them in your code.

Usage

<?php

require '../src/Autoloader.php';

Xiaoler\Blade\Autoloader::register();

use Xiaoler\Blade\FileViewFinder;
use Xiaoler\Blade\Factory;
use Xiaoler\Blade\Compilers\BladeCompiler;
use Xiaoler\Blade\Engines\CompilerEngine;
use Xiaoler\Blade\Filesystem;
use Xiaoler\Blade\Engines\EngineResolver;

$path = ['/view_path'];         // your view file path, it's an array
$cachePath = '/cache_path';     // compiled file path

$file = new Filesystem;
$compiler = new BladeCompiler($file, $cachePath);

// you can add a custom directive if you want
$compiler->directive('datetime', function($timestamp) {
    return preg_replace('/(\(\d+\))/', '<?php echo date("Y-m-d H:i:s", $1); ?>', $timestamp);
});

$resolver = new EngineResolver;
$resolver->register('blade', function () use ($compiler) {
    return new CompilerEngine($compiler);
});

// get an instance of factory
$factory = new Factory($resolver, new FileViewFinder($file, $path));

// if your view file extension is not php or blade.php, use this to add it
$factory->addExtension('tpl', 'blade');

// render the template file and echo it
echo $factory->make('hello', ['a' => 1, 'b' => 2])->render();

You can enjoy almost all the features of blade with this extension. However, remember that some of exclusive features are removed.

You can't:

  • use @inject @can @cannot @lang in a template file
  • add any events or middleawares

Documentation: http://laravel.com/docs/5.4/blade

Thanks for Laravel and it authors. That is a great project.

Comments
  • Fatal error with undefined method last when using components

    Fatal error with undefined method last when using components

    Inside \Concerns\ManagesComponents.php at line 109 the line has last($this->componentStack); which should be Arr::last($this->componentStack); and use the static class at the top use Xiaoler\Blade\Support\Arr;.

    opened by clytras 3
  • Undefined property: Xiaolin\Blade\Engines\CompilerEngine::$session

    Undefined property: Xiaolin\Blade\Engines\CompilerEngine::$session

    Problems working with sessions in codeigniter.

    A PHP Error was encountered

    Severity: Notice

    Message: Undefined property: Xiaoler\Blade\Engines\CompilerEngine::$session

    Filename: cache/877d4256ca2b11e0616b3866aa1e54f6

    opened by robertsanseries 3
  • Undefined offset: 3

    Undefined offset: 3

    protected function compileStatements($value) { $callback = function ($match) { if (strpos($match[1], '@') !== false) { $match[0] = isset($match[3]) ? $match[1].$match[3] : $match[1]; } elseif (isset($this->customDirectives[$match[1]])) { $match[0] = call_user_func($this->customDirectives[$match[1]], ($match[3] ?: '')); } elseif (method_exists($this, $method = 'compile'.ucfirst($match[1]))) { $match[0] = $this->$method(($match[3] ?: '')); }

        return isset($match[3]) ? $match[0] : $match[0].$match[2];
    };
    
    return preg_replace_callback('/\B@(@?\w+)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', $callback, $value);
    

    } xiaoler\blade\src\Compilers\BladeCompiler.php 248 line

    opened by Excas 3
  • Fatal error: require(): Failed opening required '../src/helpers.php'

    Fatal error: require(): Failed opening required '../src/helpers.php'

    I get a fatal error when I'm trying to use the example code. Am I doing something wrong?

    Warning: require(../src/helpers.php): failed to open stream: No such file or directory in /vendor/xiaoler/blade/src/Autoloader.php on line 12

    Warning: require(../src/helpers.php): failed to open stream: No such file or directory in /vendor/xiaoler/blade/src/Autoloader.php on line 12

    Fatal error: require(): Failed opening required '../src/helpers.php' (include_path='.:/opt/php56/lib/php') in /vendor/xiaoler/blade/src/Autoloader.php on line 12

    EDIT

    Just changed require '../src/helpers.php'; to require 'helpers.php'; inside the Autoloader.php and it's now working. Why do I get this error? I just C/P the sample code and created a simple view. Also why does the include use ../src/ for helpers.php, a file that it's inside the same directory with the Autoloader.php?

    opened by clytras 2
  • Argument 1 passed to Xiaoler\Blade\Compilers\Compiler::__construct()

    Argument 1 passed to Xiaoler\Blade\Compilers\Compiler::__construct()

    Hi guys,

    An uncaught Exception was encountered

    Type: TypeError

    Message: Argument 1 passed to Xiaoler\Blade\Compilers\Compiler::__construct() must be an instance of Xiaoler\Blade\Filesystem, string given, called in C:\xampp\htdocs\application\libraries\Blade.php on line 18

    Filename: C:\xampp\htdocs\vendor\xiaoler\blade\src\Compilers\Compiler.php

    Line Number: 33

    Backtrace:

    File: C:\xampp\htdocs\application\libraries\Blade.php Line: 18 Function: __construct

    File: C:\xampp\htdocs\index.php Line: 315 Function: require_once

    opened by marcuxyz 1
  • Error while registering autoloader

    Error while registering autoloader

    Hello, Im trying to do a basic render but after requiring the autoload.php and doing

    Xiaoler\Blade\Autoloader::register();

    I'm getting the following error:

    ( ! ) Warning: require(./helpers.php): failed to open stream: No such file or directory in /var/www/html/some-path/vendor/xiaoler/blade/src/Autoloader.php on line 12

    the line responsible inside Autoloader is: require './helpers.php';

    presumably because the ./

    opened by vanrez-nez 1
  • 你好, 请教一个关于laravel的 DB 基本用法迁移的问题

    你好, 请教一个关于laravel的 DB 基本用法迁移的问题

    如这里所说: http://stackoverflow.com/questions/27956821/can-i-use-dbtabletags-outside-of-laravel
    网上有很多教程移植 Eloquent , 并且可以使用成功, 如移植到 codeigniter 中, 可以直接使用 Active Record 用法(User::first());
    可是, 如何移植他的基本用法呢 ? 如: DB::table('user')->get();

    opened by fizzcome 1
  • fix issue call continue & break without condition

    fix issue call continue & break without condition

    fix error with complier “@continue” and “@break” without condition

    “ifArray continue”

    because parameter “$expression” passed as array to “compileContinue” & “compileBreak” when must to be empty if blade statement call without parameter

    opened by salkhwlani 0
  • xiaoler/blade depends on symfony/debug

    xiaoler/blade depends on symfony/debug

    The Engines/PhpEngine.php uses `Symfony\Component\Debug\Exception\FatalThrowableError´.

    In effect, this means that xiaoler/blade depends on symfony/debug.

    opened by frodeborli 0
  • 会提示一个错误这个依赖好像没有去除

    会提示一个错误这个依赖好像没有去除

    ERROR: Error: Class 'Symfony\Component\Debug\Exception\FatalThrowableError' not found in D:\phpStudy\WWW\teebphp\library\blade\src\Engines\PhpEngine.php:46 Stack trace: #0 D:\phpStudy\WWW\teebphp\library\blade\src\Engines\CompilerEngine.php(60): Xiaoler\Blade\Engines\PhpEngine->evaluatePath('D:\phpStudy\WWW...', Array) #1 D:\phpStudy\WWW\teebphp\library\blade\src\View.php(132): Xiaoler\Blade\Engines\CompilerEngine->get('D:\phpStudy\WWW...', Array) #2 D:\phpStudy\WWW\teebphp\library\blade\src\View.php(115): Xiaoler\Blade\View->getContents() #3 D:\phpStudy\WWW\teebphp\library\blade\src\View.php(82): Xiaoler\Blade\View->renderContents() #4 D:\phpStudy\WWW\teebphp\library\blade\src\Blade.class.php(51): Xiaoler\Blade\View->render() #5 [internal function]: Blade->make('admin/index', Array) #6 D:\phpStudy\WWW\teebphp\app\Component\Blade\BladeManager.php(41): call_user_func_array(Array, Array) #7 D:\phpStudy\WWW\teebphp\app\Http\AdminController.php(25): App\Component\Blade\BladeManager->__call('make', Array) #8 D:\phpStudy\WWW\teebphp\app\Http\AdminController.php(15): App\Http\AdminController->actionBlade() #9 [internal function]: App\Http\AdminController->actionIndex(Object(Teeb\Http\Request)) #10 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Controller.php(72): call_user_func_array(Array, Array) #11 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Controller.php(49): Teeb\Http\Controller->runAction('index') #12 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Core.php(73): Teeb\Http\Controller->run('index', Array) #13 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Core.php(56): Teeb\Http\Core->handleRequest('admin', Array) #14 D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Http\Core.php(45): Teeb\Http\Core->handle() #15 D:\phpStudy\WWW\teebphp\public\index.php(7): Teeb\Http\Core->run() #16 {main} [] in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Log\Logger.php:72 in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Log\Logger.php:62 in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Log\Logger.php:37 in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Log\Log.php:11 in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Exception\Handler.php:27 in D:\phpStudy\WWW\teebphp\vendor\master_who\teebframework\src\Teeb\Bootstrap\HandleException.php:44

    opened by xianzhi0520 0
  • Using {{ }} to echo string not encode utf8

    Using {{ }} to echo string not encode utf8

    I have array: $arr = ['title' => 'Tiêu đề'] I use {{}} tag to echo string in array, but it not encode to utf8 {{$arr['title']}} //=> Ti&ecirc;u đề

    opened by phamvansy 0
Releases(5.4.3)
Owner
Scholer
PHP,Golang,Linux
Scholer
View themes is a simple package to provide themed view support to Laravel.

Laravel View Themes View themes is a simple package to provide themed view support to Laravel. Installation Add alexwhitman/view-themes to the require

Alex Whitman 15 Nov 29, 2022
Laravel Composable View Composers Package - Compose View Composers from Component Composers

Laravel Virtuoso Laravel Composable View Composers Package Increase flexibility and reduce code duplication by easily composing complex View Composers

Yitzchok Willroth 68 Dec 29, 2021
A Laravel Code Generator based on your Models using Blade Template Engine

Laravel Code Generator is a PHP Laravel Package that uses Blade template engine to generate code for you. The difference between other code generators

Victor Yoalli 59 Dec 5, 2022
Snippets for blade template engine

Blade Snippets for Sublime Text Blade is a simple, yet powerful templating engine provided with Laravel PHP framework. These snippets works with blade

Alex Antonyuk 113 Jan 3, 2023
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

null 686 Dec 28, 2022
27Laracurl Laravel wrapper package for PHP cURL class that provides OOP interface to cURL. [10/27/2015] View Details

Laracurl Laravel cURL Wrapper for Andreas Lutro's OOP cURL Class Installation To install the package, simply add the following to your Laravel install

zjango 8 Sep 9, 2018
A simple `make:view` command for Laravel applications.

A simple make:view command for Laravel applications. Quickly generate a new Blade view from the console using artisan make:view. Installation You can

Ryan Chandler 10 Oct 17, 2022
Dashboard to view your http client requests in laravel application

Laravel Blanket is a package with wraps laravel http client requests and provide logs for request and response, also give option to retry any request from dashboard and more...

Ahmed waleed 215 Dec 29, 2022
Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology.

Stash View Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology. What is Russian Doll Caching ? It i

Bhushan Gaikwad 18 Nov 20, 2022
View your Laravel routes on the browser.

View your Laravel routes on the browser. This package adds a route to your Laravel application. Once you've installed this package, enter /route-list

Patompong Savaengsuk 23 Oct 28, 2022
Filament-spatie-laravel-activitylog - View your activity logs inside of Filament. ⚡️

View your activity logs inside of Filament. This package provides a Filament resource that shows you all of the activity logs created using the spatie

Ryan Chandler 45 Dec 26, 2022
This package provides a Logs page that allows you to view your Laravel log files in a simple UI

A simplistics log viewer for your Filament apps. This package provides a Logs page that allows you to view your Laravel log files in a simple UI. Inst

Ryan Chandler 9 Sep 17, 2022
A package that adds view-composer like feature to Inertia.js Laravel adapter

Kinetic A package that adds view-composer like feature to Inertia.js Laravel adapter. Use to be able to share props based on the Inertia component nam

Marvin Quezon 76 Dec 12, 2022
This package provides a Filament resource to view all Laravel sent emails.

This package provides a Filament resource to view all Laravel outgoing emails. It also provides a Model for the database stored emails. Installation Y

Ramón E. Zayas 22 Jan 2, 2023
A package that helps to group methods that mostly use for the view presentation purpose.

A package that helps to group methods that mostly use for the view presentation purpose form models to a dedicated presenter class.

Touhidur Rahman 9 Apr 26, 2022
Use Laravel's Blade templating engine outside of Laravel.

Use Laravel's Blade templating engine outside of Laravel. This package provides a standalone version of Laravel's Blade templating engine for use outs

Ryan Chandler 22 Jan 2, 2023
Durable workflow engine that allows users to write long running persistent distributed workflows in PHP powered by Laravel queues

Durable workflow engine that allows users to write long running persistent distributed workflows (orchestrations) in PHP powered by Laravel queues. Inspired by Temporal and Azure Durable Functions.

null 268 Dec 27, 2022
This package adds syntax definitions for the Laravel Blade engine.

Laravel Blade Highlighter This package adds syntax definitions for the Laravel Blade engine. Works with various Sublime Text version, for older/specif

Eric Percifield 393 Dec 24, 2022
A general-purpose parser for Laravel's Blade templating engine.

A general-purpose parser for Laravel's Blade templating engine. This is where your description should go. Try and limit it to a paragraph or two. Cons

Ryan Chandler 6 Feb 18, 2022