esdlabs / StringBladeCompiler by edgarnadal
forked from igormatkovic/StringBladeCompiler

Render Blade templates from string
10,023
0
4
Package Data
Maintainer Username: edgarnadal
Maintainer Contact: tporter@webpage-builders.com (Terre Porter)
Package Create Date: 2015-02-02
Package Last Update: 2015-02-02
Language: PHP
License: MIT
Last Refreshed: 2024-03-26 03:01:43
Package Statistics
Total Downloads: 10,023
Monthly Downloads: 4
Daily Downloads: 0
Total Stars: 0
Total Watchers: 4
Total Forks: 0
Total Open Issues: 0

String Blade Compiler

Render Blade templates from string value.

This is a fork from https://github.com/Flynsarmy/laravel-db-blade-compiler which uses Elequent model to pass in a template.

I have reworked it to allow for a generic array of the required fields to generates and return a compiled view from a blade-syntax template.

Version

This version 1 is for Laravel 4.2, version 2 is for Laravel 5.

Installation

Add the repository to composer.json:

"repositories": [
{
    "name": "wpb/string-blade-compiler",
	"url": "https://github.com/TerrePorter/StringBladeCompiler.git",
	"type": "git"
}
],

Add the package to composer.json:

"require": {
	"laravel/framework": "4.2.*",
	"wpb/string-blade-compiler": "1.*@dev"
},

Add the ServiceProvider to the providers array in app/config/app.php

'Wpb\StringBladeCompiler\StringBladeCompilerServiceProvider',

There is no need to add a Facade to the aliases array in the same file as the service provider, this is being included automatically in the ServiceProvider.

Usage

This package offers a StringView facade with the same syntax as View but accepts a Array or Array Object instance instead of path to view.

return StringView::make(
                        array(
                            // this actual blade template
                            'template'  => '{{ $token1 }}',
                            // this is the cache file key, converted to md5
                            'cache_key' => 'my_unique_cache_key',
                            // timestamp for when the template was last updated, 0 is always recompile
                            'updated_at' => 1391973007
                        ),
                        array(
                            'token1'=> 'token 1 value'
                        )
                );

Also allows for Blade::extend, example :

                        // allows for @continue and @break in foreach in blade templates
                        Blade::extend(function($value)
                        {
                          return preg_replace('/(\s*)@(break|continue)(\s*)/', '$1<?php $2; ?>$3', $value);
                        });

License

string-blade-compiler is open-sourced software licensed under the MIT license