mustache.php

A Mustache implementation in PHP.

  • Owner: bobthecow/mustache.php
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Mustache.php

PHP中的 Mustache 实现。

用法

一个简单的例子:

 <?php
$ m = new Mustache_Engine;
echo'm-> render('Hello {{planet}}',array('planet'=>'World!')); //“你好,世界!”
 

更深入的例子 - 这是规范的胡须模板:

  Hello {{name}}
您刚赢得{{value}}美元!
{{#in_ca}}
恩,{taxed_value}}美元,税后。
{{/in_ca}}
 

创建一个视图“上下文”对象 - 也可以是一个关联数组,但那些函数并不如此:

 <?php
克里斯{
    public $ name =“Chris";
    public $ value = 10000;

    public function taxed_value(){
        返回$ this->值 - ($ this->值* 0.4);
    }

    public $ in_ca = true;
}
 

并呈现它:

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

这并非全部!

阅读 Mustache.php文档了解更多信息。

另见

Main metrics

Overview
Name With Ownerbobthecow/mustache.php
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2010-03-19 10:58:58
Pushed At2025-06-28 18:37:45
Last Commit At
Release Count52
Last Release Namev3.0.0 (Posted on 2025-06-28 14:29:02)
First Release Name0.1 (Posted on 2010-04-26 21:17:26)
用户参与
Stargazers Count3.3k
Watchers Count113
Fork Count435
Commits Count0.9k
Has Issues Enabled
Issues Count283
Issue Open Count31
Pull Requests Count60
Pull Requests Open Count2
Pull Requests Close Count82
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Mustache.php

A Mustache implementation in PHP.

Package version
Build status
StyleCI
Monthly downloads

Usage

A quick example:

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

And a more in-depth example -- this is the canonical Mustache template:

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

Create a view "context" object -- which could also be an associative array, but those don't do functions quite as well:

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

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

    public $in_ca = true;
}

And render it:

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

And That's Not All!

Read the Mustache.php documentation for more information.

See Also