C++ implementation of Mustache as a PHP extension.
All features of Mustache are supported EXCEPT:
- Whitespace rules. All whitespace is kept as it is in the input template.
Prerequisite packages are:
- PHP development headers and tools
gcc>= 4.4 |clang>= 3.x |vc>= 11- GNU
make>= 3.81 automakeautoconflibmustache
git clone git://github.com/jbboehr/php-mustache.git --recursive
cd php-mustache
phpize
./configure --enable-mustache
make
sudo make installAdd the extension to your php.ini:
echo extension=mustache.so | tee -a /path/to/your/php.iniRPM packages of the extension are available in Remi's repository.
Fedora (change 24 to match your Fedora version)
dnf install https://rpms.remirepo.net/fedora/remi-release-24.rpm
dnf install --enablerepo=remi php-pecl-mustacheRHEL/CentOS (for default PHP in base repository)
yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install php-pecl-mustachenix-env -i -f https://github.com/jbboehr/php-mustache/archive/master.tar.gzSee Build your own PHP on Windows. You may need to add msinttypes (export) to your include directory.
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.
See also: template loader example
The MIT License (MIT). Please see License File for more information.