2017 © Pedro Peláez
 

library mustache

PHP Mustache Implementation

image

packfire/mustache

PHP Mustache Implementation

  • Wednesday, March 26, 2014
  • by mauris
  • Repository
  • 1 Watchers
  • 2 Stars
  • 436 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 15 Versions
  • 0 % Grown

The README.md

Packfire Mustache, (*1)

Packfire Mustache is a lightweight Mustache implementation for Packfire. Prior to the adoptation of Mustache, Packfire has used a simple token-replace templating engine that uses single curly braces to indicate tokens., (*2)

<h1>
  {title}
</h1>
<p>{message}</p>

However, the simple templating parser is way too primitive and does not support nesting and listing like Mustache does. Hence, Packfire adopted the Mustache templating engine as its default templating engine., (*3)

However, the PHP Mustache implementation by bobthecow was found to be too heavy and thus I decided to come up with our own. Mustache has been tested against the provided spec tests., (*4)

Packfire Mustache uses double curly braces to indicate tokens, supports escaping by default and supports nested block tokens:, (*5)

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

To find out more about how Packfire Mustache works you can refer to the original Mustache manual as Mustache is designed to be platform-independent and cross-platform compatible., (*6)

Installation

Packfire Mustache can be installed via Composer:, (*7)

{
    "require": {
        "packfire/mustache": "1.0.*"
    }
}

Then run the Composer installation command:, (*8)

$ composer install

Usage

A quick example:, (*9)

use Packfire\Template\Mustache\Mustache;

$m = new Mustache('Hello {{planet}}!');
echo $m->parameters(array('planet' => 'World'))->render();
// "Hello World!"

And a more in-depth example--this is the canonical Mustache template:, (*10)

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

Along with the associated Mustache class:, (*11)

use Packfire\Template\Mustache\Mustache;

class Chris extends Mustache {
    public $name = "Chris";
    public $value = 10000;

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

    public $in_ca = true;
}

Render it like so:, (*12)

$chris = new Chris;
echo $chris->template($template)->render();

Here's the same thing, a different way:, (*13)

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

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:, (*15)

use Packfire\Template\Mustache\Mustache;

$chris = new Chris();
$m = new Mustache();
echo $m->template($template)->parameters($chris)->render();

The Versions

26/03 2014

dev-master

9999999-dev

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

26/03 2014

1.2.4

1.2.4.0

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

26/03 2014

dev-develop

dev-develop

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

17/11 2013

1.2.3

1.2.3.0

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

27/10 2013

1.2.2

1.2.2.0

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

26/10 2013

1.2.1

1.2.1.0

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

24/10 2013

1.2.0

1.2.0.0

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

19/10 2013

1.1.5

1.1.5.0

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

19/10 2013

1.1.3

1.1.3.0

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

16/10 2013

1.1.2

1.1.2.0

PHP Mustache Implementation

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

16/10 2013

1.1.1

1.1.1.0

PHP Mustache Implementation

  Sources   Download

The Requires

  • php >=5.3.0

 

12/10 2013

1.1.0

1.1.0.0

PHP Mustache Implementation

  Sources   Download

The Requires

  • php >=5.3.0

 

12/10 2013

1.0.2

1.0.2.0

PHP Mustache Implementation

  Sources   Download

The Requires

  • php >=5.3.0

 

27/09 2013

1.0.1

1.0.1.0

PHP Mustache Implementation

  Sources   Download

The Requires

  • php >=5.3.0

 

24/05 2013

1.0.0

1.0.0.0

PHP Mustache Implementation

  Sources   Download

The Requires

  • php >=5.3.0