Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Mustache PHP Extension
PHP C++

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
mustache @ acc4002
spec @ 9b1bc7a
tests
.gitignore
.gitmodules
README.md
bench.php
config.m4
generate-tests.php
mustache.php
mustache_data.cpp
mustache_data.hpp
mustache_exceptions.cpp
mustache_exceptions.hpp
mustache_mustache.cpp
mustache_mustache.hpp
mustache_template.cpp
mustache_template.hpp
php_mustache.cpp
php_mustache.hpp

README.md

Mustache

C++ implementation of Mustache as a PHP extension. See http://mustache.github.com/

Features

All features of Mustache are supported EXCEPT:

  • Lambda functions
  • Whitespace rules. All whitespace is kept as it is in the input template.

Requirements

Ubuntu:

apt-get install git-core php5-dev

Installation

Ubuntu:

git clone git://github.com/jbboehr/php-mustache.git
cd php-mustache
git submodule init
git submodule update
phpize
./configure --enable-mustache
make && make install

Usage

Example:

<?php
$mustache = new Mustache();
$tmpl = <<<EOF
Hello {{name}}
You have just won {{value}} dollars!
{{#in_ca}}
Well, {{taxed_value}} dollars, after taxes.
{{/in_ca}}
EOF;
$data = array(
  'name' => 'John',
  'value' => 10000,
  'taxed_value' => 10000 * 0.6,
  'in_ca' => true,
);
$partials = array();
echo $mustache->render($tmpl, $data, $partials);

Produces:

Hello John
You have just won 10000 dollars!

Well, 6000 dollars, after taxes.

Example 2:

<?php
$mustache = new Mustache();
$tmpl = $mustache->compile('{{var}}');
$data = new MustacheData(array('var' => 'val'));
for( $i = 0; $i < 5; $i++ ) {
  echo $mustache->render($tmpl, $data);
}

Produces:

valvalvalvalval

Todo

  • Fix whitespace non-conformity
  • Cache compiled templates in memory
  • Test in thread-safe mode

Tested On

  • Ubuntu 11.10 / GCC 4.6.1 / PHP 5.3.6
  • Ubuntu 10.04 LTS / GCC 4.4.3 / PHP 5.3.2
  • FreeBSD 9.0 / GCC 4.2.1 / PHP 5.3.8
Something went wrong with that request. Please try again.