Git Product home page Git Product logo

blade's Introduction

blade

Use Laravel Blade templates as a standalone component without the full Laravel framework

Build Status Latest Stable Version

Versions

  • For Laravel 5 style escaping {!! = raw, and {{ = escaped, use version 2.* of this project.
  • For Laravel 4 style escaping {{ = raw, and {{{ = escaped, use version 1.* of this project.

Documentation

There is are two classes available with a namespace of duncan3dc\Laravel. One is for regular usage (BladeInstance) and one for static calls (Blade) facade style.

use duncan3dc\Laravel\Blade;
use duncan3dc\Laravel\BladeInstance;

The recommended way of using this library is the BladeInstance class.
The paths used for view templates and for cached files can be set by passing them to the constructor:

$blade = new BladeInstance("/var/www/views", "/var/www/cache/views");

If they are not passed, or the static Blade class is used then the Env helper is used to resolve paths.
The following paths are used:

  • views - Default directory to search for *.blade.php templates
  • cache/views - Directory to cache generated php code from the templates

Some minor extensions to blade syntax have been made, such as supporting namespaces (see examples below)

Examples

Output a basic view (from views/index.blade.php)

echo $blade->render("index");

Check multiple directories for a view (from /var/www/views/index.blade.php if it exists, otherwise /var/www/custom/views/index.blade.php)

$blade = new BladeInstance("/var/www/views");
$blade->addPath("/var/www/custom/views");
echo $blade->render("index");

Declare a namespace for the php generated from the view

@namespace(duncan3dc\Webapps\Calendar)

Import classes for use in the views

@use(duncan3dc\Helpers\Html)

{!! Html::formatKey("project_title") !!}

If you need an Illuminate\View\View object there is also a make() method available

$view = $blade->make("index");

Static Usage

Output a basic view (from views/index.blade.php)

echo Blade::render("index");

Output a view from a different directory (from /home/webapp/views/index.blade.php)

use duncan3dc\Helpers\Env;

Env::usePath("/home/webapp");
echo Blade::render("index");

Laravel

You can also use the extra functionality provided by this library inside the Laravel framework.
Just pass your Blade instance to the extendBlade() method.

\duncan3dc\Laravel\Blade::extendBlade(\App::make("blade"));

blade's People

Contributors

duncan3dc avatar

Watchers

James Cloos avatar Angel Anaya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.