本文整理汇总了PHP中Mustache_Engine类的典型用法代码示例。如果您正苦于以下问题:PHP Mustache_Engine类的具体用法?PHP Mustache_Engine怎么用?PHP Mustache_Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mustache_Engine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderHTML
protected function renderHTML()
{
$dir = rtrim($this->viewDir);
$mustache = new \Mustache_Engine(['loader' => new \Mustache_Loader_FilesystemLoader($dir)]);
$template = $mustache->loadTemplate($this->view);
return $template->render($this->data);
}
示例2: testLambdasInsidePartialsAreIndentedProperly
public function testLambdasInsidePartialsAreIndentedProperly()
{
$src = <<<EOS
<fieldset>
{{> input }}
</fieldset>
EOS;
$partial = <<<EOS
<input placeholder="{{# _t }}Enter your name{{/ _t }}">
EOS;
$expected = <<<EOS
<fieldset>
<input placeholder="ENTER YOUR NAME">
</fieldset>
EOS;
$m = new Mustache_Engine(array(
'partials' => array('input' => $partial)
));
$tpl = $m->loadTemplate($src);
$data = new Mustache_Test_Functional_ClassWithLambda();
$this->assertEquals($expected, $tpl->render($data));
}
示例3: render
/**
* render() takes a view name, and a model and renders a mustache template
*
* @param $view string The view name, which will be used to fetch the actual view
* @param $model array An array containing all of the fields that will be passed to mustache for render
*
* @return string
*/
function render($view, $model)
{
$m = new Mustache_Engine(['loader' => new Mustache_Loader_FilesystemLoader(PREFIX . '/views')]);
$tpl = $m->loadTemplate($view);
header("Content-Type: text/html; charset=utf-8");
echo minify_output($tpl->render($model));
}
示例4: show_news
public static function show_news($folder = 'posts', $template = 'templates')
{
$m = new Mustache_Engine();
$files = glob("{$folder}/*.md");
/** /
usort($files, function($a, $b) {
return filemtime($a) < filemtime($b);
});
/**/
$html = '';
foreach ($files as $file) {
$route = substr($file, strlen($folder) + 1, -3);
$page = new FrontMatter($file);
$title = $page->fetch('title') != '' ? $page->fetch('title') : $route;
$date = $page->fetch('date');
$author = $page->fetch('author');
$description = $page->fetch('description') == '' ? '' : $page->fetch('description');
$data[] = array('title' => $title, 'route' => $route, 'author' => $author, 'description' => $description, 'date' => $date);
}
/**/
function date_compare($a, $b)
{
$t1 = strtotime($a['date']);
$t2 = strtotime($b['date']);
return $t1 - $t2;
}
usort($data, 'date_compare');
$data = array_reverse($data);
/**/
$template = file_get_contents('templates/show_news.tpl');
$data['files'] = $data;
return $m->render($template, $data);
return $html;
}
示例5: render
public function render()
{
$m = new \Mustache_Engine();
$template = $this->template->contents();
$output = $m->render($template, $this->context);
$this->output->write($output);
}
示例6: makeMustache
/**
* Compiles plugin's mustache template
*/
public function makeMustache()
{
$dir = __DIR__ . '/views/cache';
$this->_cleanDir($dir);
$mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader(__DIR__ . '/views'), 'cache' => $dir));
$mustache->loadTemplate('laps');
}
示例7: render
/**
* Renders a template using Mustache.php.
*
* @see View::render()
* @param string $template The template name specified in Slim::render()
* @return string
*/
public function render($template)
{
require_once self::$mustacheDirectory . '/Autoloader.php';
\Mustache_Autoloader::register(dirname(self::$mustacheDirectory));
$m = new \Mustache_Engine();
$contents = file_get_contents($this->getTemplatesDirectory() . '/' . ltrim($template, '/'));
return $m->render($contents, $this->data);
}
示例8: vimeography_add_mce_popup
/**
* Action target that displays the popup to insert a form to a post/page.
*
* @access public
* @return void
*/
public function vimeography_add_mce_popup()
{
$mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader(VIMEOGRAPHY_PATH . 'lib/admin/templates')));
require_once VIMEOGRAPHY_PATH . 'lib/admin/controllers/vimeography/mce.php';
$view = new Vimeography_MCE();
$template = $mustache->loadTemplate('vimeography/mce');
echo $template->render($view);
}
示例9: getActions
/**
* Uma action nesse contexto representa o link que executa uma ação específica
* em um grid, específicamente na última coluna do grid, na coluna AÇÕES.
*
* @param Mustache_Engine $mustache
* @param array $row
*/
public function getActions($mustache, $row)
{
$actions = "";
foreach ($this->actions as $config) {
$actions .= " " . HTML::link($mustache->renderHTML($config['url'], $row), '<span class="' . $config['icon_class'] . '"></span> ' . $config['label_text'] . ' ', $config['title'], $config['extra']);
}
return $actions;
}
示例10: testCallEatsContext
public function testCallEatsContext()
{
$m = new Mustache_Engine();
$tpl = $m->loadTemplate('{{# foo }}{{ label }}: {{ name }}{{/ foo }}');
$foo = new Mustache_Test_Functional_ClassWithCall();
$foo->name = 'Bob';
$data = array('label' => 'name', 'foo' => $foo);
$this->assertEquals('name: Bob', $tpl->render($data));
}
示例11: mustacheRender
public static function mustacheRender($template, $values)
{
TemplateEngine::getMustacheInstance();
$m = new Mustache_Engine();
//
$response = $m->render($template, $values);
// $response = preg_replace('/[\s\t\n\r\s]+/', ' ', $response);
return $response;
}
示例12: page
public static function page($arr, $templ_short)
{
$mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader(dirname(__DIR__) . '/templ/')));
// Add urls into Arr
$arr['mainUrl'] = main_url;
$arr['siteUrl'] = site_url;
$_templ = $mustache->loadTemplate($templ_short);
echo $_templ->render($arr);
}
示例13: getMustache
/**
* Get a Mustache object.
*
* @param Container $c A DI container.
*
* @return \Mustache_Engine
*
* @since 2.0
*/
public function getMustache(Container $c)
{
$config = $c->get('config');
$mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($config->get('mustache.views', __DIR__ . '/../templates'), array('extension' => $config->get('mustache.ext', '.md')))));
$mustache->addHelper('number', array('1f' => function ($value) {
return sprintf('%.1f', $value);
}));
return $mustache;
}
示例14: testStrictCallablesEnabled
/**
* @group wip
* @dataProvider strictCallables
*/
public function testStrictCallablesEnabled($name, $section, $expected)
{
$mustache = new Mustache_Engine(array('strict_callables' => true));
$tpl = $mustache->loadTemplate('{{# section }}{{ name }}{{/ section }}');
$data = new StdClass();
$data->name = $name;
$data->section = $section;
$this->assertEquals($expected, $tpl->render($data));
}
示例15: getAddComment
public function getAddComment()
{
$mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($this->path_template), 'helpers' => array('i18n' => \Aoloe\Senape\I18n::getInstance($this->settings))));
$template = $mustache->loadTemplate('comment-form-add');
// \Aoloe\debug('settings', $this->settings);
// TODO: translating in the template or here in php before handing over to the template?
// TODO: pass the current values once and if we have them
return $template->render(array('has-labels' => false, 'site-current' => $this->settings['senape-site-current'], 'page-current' => $this->settings['senape-page-current'], 'comment-last-id' => null));
}