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文档了解更多信息。

另见

Overview

Name With Ownerbobthecow/mustache.php
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:MIT License
Release Count50
Last Release Namev2.14.2 (Posted on 2022-08-23 09:07:12)
First Release Name0.1 (Posted on 2010-04-26 21:17:26)
Created At2010-03-19 10:58:58
Pushed At2023-06-11 02:16:53
Last Commit At
Stargazers Count3.2k
Watchers Count115
Fork Count421
Commits Count858
Has Issues Enabled
Issues Count278
Issue Open Count35
Pull Requests Count54
Pull Requests Open Count5
Pull Requests Close Count76
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

To the top