openemr/mustache

PHP中的Mustache实现。

v2.15.2 2022-03-03 14:53 UTC

README

PHP中的Mustache实现。

Package version Build status StyleCI Monthly downloads

使用方法

快速示例

<?php
$m = new Mustache_Engine(array('entity_flags' => ENT_QUOTES));
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(array('entity_flags' => ENT_QUOTES));
$chris = new Chris;
echo $m->render($template, $chris);

注意:我们建议将entity_flags作为默认值使用ENT_QUOTES来减少跨站脚本漏洞的风险。

不仅如此!

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

另请参阅