承接 brightmachine/laratash 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brightmachine/laratash

Composer 安装命令:

composer require brightmachine/laratash

包简介

A Laravel 5+ wrapper for mustache.php, a PHP implementation of http://mustache.github.io/

README 文档

README

A Laravel wrapper for mustache.php, a PHP implementation of http://mustache.github.io/

Acknowledgements

This project is based entirely on the the mustache-l4 package by Conar Welsh and contributors.

Supports

  • Laravel 5
  • mustache/mustache 2.7+

Installation

Add laratash as a dependency to your composer.json file:

"require": {
	"laravel/framework":      "~5.0",
	"brightmachine/laratash": "~5.0"
}

run composer update, or composer install if this is a brand new project

Add the Service Provider

Open: config/app.php

...

'Laratash\LaratashServiceProvider',
	
...

You are all setup!

Usage

Laratash is merely a wrapper for the Mustache.php library that integrates it into Laravel 5+.

Laratash registers itself with the Laravel View class, providing seamless integration with Laravel. You can use Mustache just as you would Blade! The Laravel View class will choose the right template engine to use based on the file extension of the view. So all you have to do to render Mustache files, is ensure that your view has a .mustache file extension. Laratash will take care of the rest.

You can even mix and match template engines. For instance maybe you have a Blade layout file, and you want to nest a Mustache view, that's fine! However just be aware of the fact that Mustache does not understand Block Sections like Blade does. The Mustache view will be rendered into a variable named whatever section you passed the view to. So for example if you were to do:

$view->nest('content', 'some.view');
$view->nest('sidebar', 'some.sidebar');

The contents of the parsed some.view file will be available in the template file under a variable called $content. The contents of the parsed some.sidebar would be available in the template file, under a variable called $sidebar.

By default, Mustache partials are also loaded using Laravel's ViewFinder, so you can feel free to use dot-notation to specify a view.

{{#posts}}
	{{> posts._post}}
{{/posts}}

Other than that it is business as usual!

Examples:

  • Example using View::make()

    app/views/test.mustache

      <h1>{{ pageHeading }}</h1>
      <div>
      	{{ pageContent }}
      </div>
    

    app/router.php

      Route::get('/', function()
      {
      	return View::make('test', array(
      		'pageHeading' => 'Rendered with Mustache.php',
      		'pageContent' => 'But still looks like Laravel!'
      	));
      });
    
  • Example using a Blade controller layout

    app/views/layouts/master.blade.php

      <html>
      <head></head>
      <body>
      	{{-- since Mustache does not use sections, the nested section will instead
      	be rendered as a variable --}}
      	{{ content }}
      </body>
      </html>
    

    app/views/test.mustache

      <h1>{{ pageHeading }}</h1>
      <div>
      	{{ pageContent }}
      </div>
    

    app/controllers/TestController.php

      <?php
    
      class TestController extends BaseController {
      
          public $layout = 'layouts.master';
          
          public function index()
          {
       	$this->layout->nest('content', 'test', array(
       		'pageHeading' => 'Rendered with Mustache.php',
      		'pageContent' => 'But still looks like Laravel!'
       	));   
          }
          
      	}
    
  • Example using a Mustache layout

    app/views/posts/_post.mustache

      <article>
      	<h2>{{ title }}</h2>
      	<div>
      		{{ content }}
      	</div>
      </article>
    

    app/views/blog/index.mustache

      <html>
      <head></head>
      <body>
      	<h1>My Blog</h1>
      	
      	{{#posts}}
      		{{> posts._post}}
      	{{/posts}}
      </body>
      </html>
    

    app/routes.php

      Route::get('/', function()
      {
      	$posts = array(
      		array(
      			'title' => 'This is a Title',
      			'content' => 'lorem ipsum...'
      		),
      		array(
      			'title' => 'This is a another title',
      			'content' => 'lorem ipsum...'
      		),
      		array(
      			'title' => 'This is yet another Title',
      			'content' => 'lorem ipsum...'
      		),
      	);
      	
      	return View::make('blog.index', compact('posts));
      });
    

A note on template data

Laravel expects view data to be be passed as an array.

Mustache PHP, however, also allows a Context object to be used.

If you wish to use a Context object, pass through an array with a __context key and this will be used. E.g.

`return view('my.view', ['__context' => new Context]);`

Configure

You can alter the configuration options that are passed to Mustache.php in your ConfigServiceProvider. E.g.

config([
	'laratash.cache' => storage_path() . '/framework/views/mustache',
]);

All laratash. options are passed directly to the Mustache_Engine constructor, so you can use any of the options that you would use with Mustache.php

brightmachine/laratash 适用场景与选型建议

brightmachine/laratash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.8k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2014 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「mustache」 「laravel」 「laravel 5」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 brightmachine/laratash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 brightmachine/laratash 我们能提供哪些服务?
定制开发 / 二次开发

基于 brightmachine/laratash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-20