Template mustache.php (ok)

https://github.com/bobthecow/mustache.php

C:\xampp\htdocs\mustache.php\index.php

<?php
require 'vendor/autoload.php';
Mustache_Autoloader::register();
// $m = new Mustache_Engine;
// echo $m->render('Hello, {{planet}}!', array('planet' => 'World'));
$mustache = new Mustache_Engine(array(
  'template_class_prefix'  => '__MyTemplates_',
  'cache'                  => dirname(__FILE__) . '/tmp/cache/mustache',
  'cache_file_mode'        => 0666, // Please, configure your umask instead of doing this :)
  'cache_lambda_templates' => true,
  'loader'                 => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views'),
  'partials_loader'        => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views/partials'),
  'helpers'                => array('i18n' => function ($text) {
    // do something translatey here...
  }),
  'escape'                 => function ($value) {
    return htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
  },
  'charset'                => 'ISO-8859-1',
  'logger'                 => new Mustache_Logger_StreamLogger('php://stderr'),
  'strict_callables'       => true,
  'pragmas'                => [Mustache_Engine::PRAGMA_FILTERS],
));
$tpl = $mustache->loadTemplate('foo'); // loads __DIR__.'/views/foo.mustache';
echo $tpl->render(array('bar' => 'baz','value'=> 123, 'taxed_value'=>5000,'in_ca'=> array('taxed_value' => 3456)));

C:\xampp\htdocs\mustache.php\views\foo.mustache

<h1>Hello {{bar}}</h1>
<h3>You have just won {{value}} dollars!</h3>
{{#in_ca}}
  <p>Well, {{taxed_value}} dollars, after taxes.</p>
{{/in_ca}}

Last updated