chh/mustache-js-compiler 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

chh/mustache-js-compiler

Composer 安装命令:

composer require chh/mustache-js-compiler

包简介

Compiles server-side Mustache templates to self-sufficient client-side JS functions

关键字:

README 文档

README

Compiles server-side Mustache templates to self-sufficient client-side JS functions. Uses the excellent PhlyMustache.

Install

composer require 'chh/mustache-js-compiler':~1.0@dev

Usage

The compiler needs an instance of Phly\Mustache\Mustache to function.

If you intend to share templates between the server and the client, than it's recommended to use the same Mustache instance which your application uses so the template paths are setup the same way (for partials to be compiled correctly).

<?php

$mustache = new Phly\Mustache\Mustache;
// or use the same Mustache environment than your application:
$mustache = $app['mustache'];

Then create the compiler and pass it the Mustache environment:

$jsCompiler = new CHH\MustacheJsCompiler\MustacheJsCompiler($mustache);

The compiler has a compile method which works the same way as $mustache->tokenize(). It looks up the template name in the template path, or uses the passed Mustache code. The compile method returns a self-sufficient JavaScript function which executes the template.

The template looks like this:

{{! user/show.mustache }}
Hi {{name}}!

We can render the template using this code:

<div id="user-widget"></div>
<script>
  (function() {
    var template = <?php echo $jsCompiler->compile('user/show') ?>;
    var widget = document.getElementById('user-widget');
    widget.innerHTML = template({name: "Christoph"});
  })();
</script>

Unimplemented Mustache Features

  • Filters

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固