brunodebarros/mustache.php

PHP 的 Mustache 实现,基于 @bobthecow 的版本。

v50.0 2015-08-28 02:02 UTC

README

PHP 中的 Mustache 实现。

Package version Build status Monthly downloads

用法

快速示例

<?php
$m = new Mustache_Engine;
echo $m->render('Hello {{planet}}', array('planet' => 'World!')); // "Hello World!"

更深入的示例 -- 这是标准的 Mustache 模板

Hello {{name}}
You have just won {{value}} dollars!
{{#in_ca}}
Well, {{taxed_value}} dollars, after taxes.
{{/in_ca}}

创建一个视图 "上下文" 对象 -- 这也可以是一个关联数组,但它们在处理函数方面并不那么出色

<?php
class Chris {
    public $name  = "Chris";
    public $value = 10000;

    public function taxed_value() {
        return $this->value - ($this->value * 0.4);
    }

    public $in_ca = true;
}

并渲染它

<?php
$m = new Mustache_Engine;
$chris = new Chris;
echo $m->render($template, $chris);

还有更多!

阅读 Mustache.php 文档 以获取更多信息。

相关链接