spiasecki/mustache

PHP中命名空间化的Mustache实现。

v2.7.0 2014-09-06 10:37 UTC

This package is not auto-updated.

Last update: 2024-09-10 02:46:38 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}}!
{{#in_ca}}
Well, ${{taxed_value}}, 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文档获取更多信息。

另请参阅