GithubHelp home page GithubHelp logo

olubunmitosin / views Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 27 KB

Lara standalone blade view that enables the use of laravel view outside laravel project

License: Other

PHP 99.62% HTML 0.38%

views's Introduction

The Lara Blade View | Blade Template Outside Laravel

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Laravel Blade Views Standalone

Okay so by now hopefully you have heard of Laravel, the PHP framework that just makes things easy. So first things first full credit goes to Taylor Otwell and Brad Jones for the Blade API.

How to Install

Installation via composer is easy:

composer require kesty/view: dev-master

How to Use

In your legacy - non Laravel application. You can use the Laravel Blade API like so:

// Make sure you have composer included
require('vendor/autoload.php');

// Create a new View Instance
$views = new Lara\View('/path/to/my/views');

// Next you will probably want to make the view object global.
$views->globalise();

And thats it, now you can use code like the following:

echo View::make('greeting', array('name' => 'Mike'));

Where the view might look like:

<!-- View stored in /path/to/my/views/greeting.php -->

<html>
    <body>
        <h1>Hello, <?php echo $name; ?></h1>
    </body>
</html>

For more info on the View API it's self see: http://laravel.com/docs/responses#views http://laravel.com/docs/templates#blade-templating

View Scope

When you run $views->globalise(); it checks to see if the class View exists globally. If not it use the function class_alias to alias it's self in much the same a Laravel Application does.

This enables us to use the View API we are familar with.

View Include Path:

You can provide an array of paths, instead of just one path. So in effect you can have a View Include Path. Very handy for setting up a HMVC type system. Here is an example:

$views = new Lara\View(['/views/specific', '/views/generic']);

So now for the why?

While laravel is so awesomely cool and great. If you want to pull a feature out and use it in another project it can become difficult. Firstly you have to have an innate understanding of the IoC Container.

You then find that this class needs that class which then requires some other config variable that is normally present in the IoC when run inside a normal Laravel App but in your case you haven't defined it and don't really want to define that value because it makes no sense in your lets say legacy application.

Perfect example is when I tried to pull the session API out to use in wordpress. It wanted to know about a booted method, which I think comes from Illuminate\Foundation\Application. At this point in time I already had to add various other things into the IoC to make it happy and it was the last straw that broke the camels back, I chucked a coders tantrum, walked to the fridge, grabbed another Redbull and sat back down with a new approach.

The result is this project.


Original Code by Brad Jones - [email protected] Maintained and Updated by Olubunmi Tosin - [email protected]

views's People

Watchers

James Cloos avatar Canaan Etaigbenu 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.