openemr / mustache
PHP中的Mustache实现。
v2.15.2
2022-03-03 14:53 UTC
Requires
- php: >=5.2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ~1.11
- phpunit/phpunit: ~3.7|~4.0|~5.0
This package is not auto-updated.
Last update: 2024-09-15 05:34:18 UTC
README
PHP中的Mustache实现。
使用方法
快速示例
<?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文档获取更多信息。