evertt / slade
受 Ruby Slim 和 Laravel Blade 启发的 Laravel 模板引擎
dev-master
2015-08-20 12:50 UTC
Requires
- php: >=5.5.0
- doctrine/inflector: ~1.0
- illuminate/view: ^5.1
Requires (Dev)
- phpspec/phpspec: ~2.1
This package is not auto-updated.
Last update: 2024-09-28 17:38:29 UTC
README
一个受 Ruby Slim 和 Laravel Blade 双方启发的 PHP 模板引擎
免责声明
我想告诉您,我认为这段代码还没有准备好投入生产。它缺少一些特性使其变得强大,尽管我已经编写了测试,但我肯定还有我遗漏的重要错误。我真正希望的是,如果您想测试它,查看代码,并给我提供建议和 pull-requests 以改进它。
安装
使用
composer require evertt/slade
将此包包含到您的 Laravel 项目中。然后在 config/app.php
中将 Slade\ServiceProvider::class
添加到您的服务提供者列表中。
使用方法
要使用此引擎,您只需创建以 .slade.php
结尾的模板文件,而不是 .blade.php
。
示例
以下模板
doctype html
html
head
title Slade
link href="style.css"
css:
body {
color: #333;
}
body
h1 My first Slade template!
? $name
p
| Hello $name, this line only appears
| if the name variable contains a truthy.
! $name
p There is no name.
div
<p>
It also works fine with just plain html.
</p>
h2 Here is a list of names of people:
ul
> $people
li = $person->name
+ elements.footer
可以解析成以下 HTML
<!DOCTYPE html> <html> <head> <title>Slade</title> <link href="style.css"> <style> body { color: #333; } </style> </head> <body> <h1>My first Slade template!</h1> <p> Hello John Doe, this line only appears if the name variable contains a truthy. </p> <div> <p> It also works fine with just plain html. </p> </div> <h2>Here is a list of names of people:</h2> <ul> <li>Harry</li> <li>Ron</li> <li>Hermione</li> </ul> <footer> © Me 2015 </footer> </body> </html>
您也可以以这种方式扩展另一个模板
_ layouts.default
@ content
p This paragraph will be assigned to the 'content' section
这将扩展例如 layouts/default.slade.php
,并且段落将出现在 layouts/default.slade.php
中包含以下行的任何位置
- content
插入变量
如您所见,您可以用几种方式插入变量。我想展示更多。
p
| So this is a block of text in which you can put variables.
You can do that in the following manner:
$var or {$var} or ${var}. The {} syntax only works if
there's no whitespace after the { and before the } though.
And finally you can also execute function calls like so:
{implode(' ', $var)}. Again, make sure there's no whitespace
immediately following the { or immediately preceding the }.
更多
您可以做很多事情。我打算很快写一个更完整的维基百科。如果您想为文档或代码做出贡献或提出任何功能建议,请提交问题或提交 pull-request。那将是我最大的礼物。