PHP code example of mustache / silex-provider
1. Go to this page and download the library: Download mustache/silex-provider library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mustache / silex-provider example snippets
$app->register(new Mustache\Silex\Provider\MustacheServiceProvider, array(
'mustache.path' => __DIR__.'/../views',
'mustache.options' => array(
'cache' => __DIR__.'/../tmp/cache/mustache',
),
));
$app->get('/hello/{name}', function ($name) use($app) {
return $app['mustache']->render('hello', array(
'name' => ucfirst($name),
));
});
// ...
$app->register(new MustacheServiceProvider, array(
'mustache.loader' => new Mustache_Loader_InlineLoader(__FILE__, __COMPILER_HALT_OFFSET__)
));
$app->get('/{name}', function($name) use ($app) {
return $app['mustache']->render('hello', compact('name'));
})
->value('name', 'world');
// ...
__halt_compiler();
@@ hello
Hello, {{ name }}!
use Silex\Application;
class MyApplication extends Application
{
use \Mustache\Silex\Application\MustacheTrait;
}
$app = new MyApplication;
return $app->render('hello', array('name' => 'Justin'));
$response = new Response;
$response->setTtl(10);
return $app->render('hello', array('name' => 'Justin'), $response);
$app['mustache'] = $app->share($app->extend('mustache', function ($mustache, $app) {
$mustache->addHelper('app', $app);
$mustache->setLogger($app['monolog']);
return $mustache;
}));
php composer.phar install