我可以在Laravel之外使用Blade模板引擎吗? [英] Can I use the Blade templating engine outside of Laravel?

查看:290
本文介绍了我可以在Laravel之外使用Blade模板引擎吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个设计模式并使用刀片模板引擎". 我可以在Laravel之外使用Blade模板引擎,并以新模式使用它吗?

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 ?

推荐答案

记录下来:

我测试了许多库以在Laravel之外运行刀片服务器(我不使用),并且大多数都是原始库的可怜的黑客,这些库只是复制并粘贴了代码并删除了一些依赖关系,但它保留了Laravel的许多依赖关系.

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.

因此,我(为一个项目)创建了一个刀片替代方案,使其在单个文件中免费(MIT许可证,即关闭源/私有代码即可)并且没有外部库的单个依赖项.您可以下载该类并开始使用它,也可以通过composer安装.

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

没有Laravel自己的功能(扩展名),它100%兼容.

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

工作原理:

<?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"]);
?>

另一种替代方法是使用树枝,但我对其进行了测试,但我不喜欢它.我喜欢Laravel的语法,它的语法接近ASP.NET MVC Razor.

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.

到目前为止(2018年7月),它实际上是唯一支持不带Laravel的Blade 5.6新功能的模板系统. ;-)

这篇关于我可以在Laravel之外使用Blade模板引擎吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆