Code Monkey home page Code Monkey logo

php-mustache's Introduction

php-mustache

GitHub Linux Build Status GitHub OSX Build Status GitHub Docker Build Status Coverage Status Software License

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/OSX

Source

Prerequisite packages are:

  • PHP development headers and tools
  • gcc >= 4.4 | clang >= 3.x | vc >= 11
  • GNU make >= 3.81
  • automake
  • autoconf
  • libmustache
git clone git://github.com/jbboehr/php-mustache.git --recursive
cd php-mustache
phpize
./configure --enable-mustache
make
sudo make install

Add the extension to your php.ini:

echo extension=mustache.so | tee -a /path/to/your/php.ini

Fedora/RHEL/CentOS

RPM 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-mustache

RHEL/CentOS (for default PHP in base repository)

yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install php-pecl-mustache

Nix/NixOS

nix-env -i -f https://github.com/jbboehr/php-mustache/archive/master.tar.gz

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.

Credits

License

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

php-mustache's People

Contributors

jbboehr avatar adambaratz avatar remicollet avatar cmb69 avatar sunpoet avatar stubbs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.