Mustache PHP Extension
PHP C++ M4 Other
Latest commit 3ddd552 Nov 16, 2016 @jbboehr committed on GitHub Merge pull request #32 from jbboehr/hotfix/centos-to-string
Fix compilation issue on CentOS 6 (Fixes #31)
Permalink
Failed to load latest commit information.
spec @ 72233f3
tests Test for indirect zvals Apr 20, 2016
.gitignore
.gitmodules
.travis.yml
LICENSE.md
README.md
ax_cxx_compile_stdcxx_11.m4
bench.php
config.m4
config.w32
generate-tests.php
mustache.php
mustache_ast.cpp
mustache_ast.hpp
mustache_class_method_lambda.cpp
mustache_class_method_lambda.hpp
mustache_code.cpp
mustache_code.hpp
mustache_data.cpp
mustache_data.hpp
mustache_exceptions.cpp
mustache_exceptions.hpp
mustache_lambda.cpp
mustache_lambda.hpp
mustache_lambda_helper.cpp
mustache_lambda_helper.hpp
mustache_mustache.cpp
mustache_mustache.hpp
mustache_private.hpp
mustache_template.cpp
mustache_template.hpp
mustache_zend_closure_lambda.cpp
mustache_zend_closure_lambda.hpp
php_mustache.cpp
php_mustache.h
php_mustache.hpp
test_mem.sh

README.md

php-mustache

Software License Build Status Coverage Status

C++ implementation of Mustache as a PHP extension.

Features

All features of Mustache are supported EXCEPT:

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

Installation

Linux

For Ubuntu LTS, the extension is available in a PPA, or via source:

Install libmustache

sudo apt-get install git-core php5-dev
git clone git://github.com/jbboehr/php-mustache.git --recursive
cd php-mustache
phpize
./configure --enable-mustache
make
sudo make install
echo extension=mustache.so | sudo tee /etc/php5/conf.d/mustache.ini

OSX

You can install the PHP Mustache extension & the libmustache dependancy on OSX using Homebrew

brew install php56-mustache

Homebrew has versions of Mustache available for PHP 5.3 - 5.6, just replace 56 above with the version you want; libmustache is a dependancy of the extension so you don't need to install it separately.

Windows

See Build your own PHP on Windows. You may need to add msinttypes (export) to your include directory.

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->execute($tmpl, $data);
}

Produces:

valvalvalvalval

Credits

License

The MIT License (MIT). Please see License File for more information.