bkwld/laravel-pug
Composer 安装命令:
composer require bkwld/laravel-pug
包简介
Pug view adapter for Laravel
README 文档
README
A small package that adds support for compiling Pug (Jade) templates to Laravel via Pug.php (see complete documentation). Both vanilla php and Blade syntax is supported within the view.
This is the documentation for the ongoing version 2.0. Click here to load the documentation for 1.11
Installation
First you need composer if you haven't yet: https://getcomposer.org/download/
Now open a terminal at the root of your Laravel project. If it's a new project,
create it with: composer create-project --prefer-dist laravel/laravel my-new-project
(replace my-new-project with your own project name,
see the documentation for further information)
Then run:
composer require bkwld/laravel-pug
Usage
Route::get('/', function () { return view('my-page'); });
Will now try to load views/my-page.pug first, or views/my-page.blade.pug
or fallback to the default blade engine loading views/my-page.blade.php.
As with Blade, you can pass variables to your view:
Route::get('/', function () { return view('my-page', [ 'user' => Auth::user(), 'messages' => ['Hello', 'Bye'], ]); });
Any file with the extension .pug will be compiled as a pug template.
Laravel Pug also registers the .pug.blade which also compile blade code
once Pug code has been compiled; but
we highly recommend you to use the clean and standard extension .pug
that will be recognized by most systems. It compiles your Pug templates
in the same way as Blade templates; the compiled template is put in your
storage directory. Thus, you don't suffer compile times on every page load.
In other words, just put your Pug files in the regular views directory
and name them like whatever.pug. You reference them in Laravel like normal
such as view('home.whatever') for resources/views/home/whatever.pug.
The Pug view files can work side-by-side with regular PHP views.
Use Blade in Pug templates
This feature is designed for transition purpose, since every blade features are available in pug, you would not need both.
To use Blade templating within your Pug, just name the files with
.blade.pug extensions.
Read more
Be aware that this mode will first render your template with pug, then give the output to render to blade, it means your template must have a valid pug syntax and must render a valid blade template. This also means blade directives are only available through pug text output, see the example below:
| @if ($one === 1)
div $one = 1
| @endif
p {{ $two }}
If you render this with the following values: ['one' => 1, 'two' => 2], you
will get:
<div>$one = 1</div> <p>2</p>
PS: note that you would get the same output with the following pure pug code:
if one === 1 div $one = 1 p=two
Use in Lumen
Register the service in bootstrap/app.php
(Register Service Providers section is the dedicated place):
$app->register(Bkwld\LaravelPug\ServiceProvider::class);
Then you can use it with view():
$router->get('/', function () use ($router) { // will render resources/views/test.pug return view('test', [ 'name' => 'Bob', ]); });
Configuration
All Pug.php options are passed through via a Laravel config array file you can edit /config/laravel-pug.php
If for any reason, the config file is missing, just run the following command:
php artisan vendor:publish --provider="Bkwld\LaravelPug\ServiceProvider"
Extending Layouts / Include Sub-views
Default root directory for templates is resources/views, so from any
template any deep in the directory, you can use absolute paths to get
other pug files from the root: extends /layouts/main will extends the file resources/views/layouts/main.pug, include /partial/foo/bar, will include resources/views/partial/foo/bar.pug. You can use the basedir option to set the root to an other directory. Paths that does not start with a slash will be resolved relatively to the current template file.
History
Read the Github project releases for release notes.
bkwld/laravel-pug 适用场景与选型建议
bkwld/laravel-pug 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68.33k 次下载、GitHub Stars 达 157, 最近一次更新时间为 2016 年 07 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bkwld/laravel-pug 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bkwld/laravel-pug 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 68.33k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 158
- 点击次数: 11
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-19