Can I use the Blade templating engine outside of L

2019-04-26 16:33发布

i'm want to creating a design pattern and use the "Blade templating engine". Can I use the Blade templating engine outside of Laravel and use it in my new pattern ?

3条回答
小情绪 Triste *
2楼-- · 2019-04-26 17:03

Yes you can use it where ever you like. Just install one of the the many packages available on composer for it.

If you're interested in integrating it with codeigniter I have a blog post here outlining the process here: http://mstd.eu/index.php/2017/03/02/using-the-laravel-blade-templating-engine-in-codeigniter-3/

Following the above steps should make it obvious how to include it into any framework.

查看更多
Deceive 欺骗
3楼-- · 2019-04-26 17:07

You certainly can, there are lots of standalone blade options on packagist, as long as you are comfortable with composer then there should be no issue, this one looks pretty interesting due to having a really high percentage of stars compared to downloads.

Be warned though i have not tried it myself, like you i was looking for a standalone option for my own project and came across it, i will be giving it a real good workout though at sometime in the near future,

查看更多
做自己的国王
4楼-- · 2019-04-26 17:12

For the record:

I tested many libraries to run blade outside Laravel (that i don't use) and most are poor hacks of the original library that simply copied and pasted the code and removed some dependencies yet it retains a lot of dependencies of Laravel.

So I created (for a project) an alternative for blade that its free (MIT license, i.e. close source/private code is OK) in a single file and without a single dependency of an external library. You could download the class and start using it, or you could install via composer.

https://github.com/EFTEC/BladeOne

https://packagist.org/packages/eftec/bladeone

It's 100% compatible sans the Laravel's own features (extensions).

How it works:

<?php
include "lib/BladeOne/BladeOne.php";
use eftec\bladeone;

$views = __DIR__ . '/views'; // folder where is located the templates
$compiledFolder = __DIR__ . '/compiled';
$blade=new bladeone\BladeOne($views,$compiledFolder);
echo $blade->run("Test.hello", ["name" => "hola mundo"]);
?>

Another alternative is to use twig but I tested it and I don't like it. I like the syntax of Laravel that its close to ASP.NET MVC Razor.

Edit: To this date (July 2018), it's practically the only template system that supports the new features of Blade 5.6 without Laravel. ;-)

查看更多
登录 后发表回答