mustache.php

How to dynamically load partials in Mustache PHP?

痞子三分冷 提交于 2019-12-13 01:33:55
问题 I'm having trouble finding decent docs on loading partials programmatically through Mustache. I'm trying to load a login page with the form being a partial (it'll change depending on different user interactions). PHP: $m = new Mustache_Engine(array( 'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views'), 'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views/login/partials') )); $params = array(); $partials = array( 'login_area' => 'login

How to use function wrapper in mustache.php?

瘦欲@ 提交于 2019-12-11 00:08:16
问题 I'm starting to work with Mustache on PHP and I don't manage to make wrapper functions to work as debt. I have this template {{#skill_level}} <span class="stars"> {{#stars}} {{skill_level}} {{/stars}} </span> {{/skill_level}} And I have this data $data = new StdClass; $data->skill_level = 3; $data->stars = function($level) { $aux = ""; $l = intVal($level); for ($i = 0; $i < $l; $i++) { $aux .= "+"; } for ($i = $l; $i < 5; $i++) { $aux .= "."; } return $aux; }; I render m.render($tenplate,

Rendering Mustache Block with external templates

眉间皱痕 提交于 2019-12-08 00:08:59
问题 I'm using Mustache 2.7.0 and trying to play with Blocks pragma for the first time. Basically, I call basic.mustache {{< layout }} {{$ title}}{{page.meta.name}}{{/ title}} {{/ layout }} calling the block layout.mustache <!DOCTYPE html> <html> <head></head> <body> <h1>{{$ title}}test{{/ title}}</h1> </body> </html> I see the value of page.meta.name appear on the page, but not the tags written in layout.mustache . Anyone have an idea why? PHP $mustache = new Mustache_Engine(array( 'pragmas' =>

PHP Mustache. Implicit iterator: How to get key of current value(numeric php array)

依然范特西╮ 提交于 2019-12-07 01:02:39
问题 If I have php array like this: $a = array ( 99 => 'Something1', 184 => 'Something2', ); And keys present important information - It can be some constant values, ids e.t.c Then how can I get key of current element from templete. For example: {{#data}} {.} - it is current value, but I need key also. {{/data}} In our system too much these kind of arrays and it is uncomfortably re-parse them before. What's better solution for this? Thank you very much! 回答1: It is not possible to iterate over an

Rendering Mustache Block with external templates

ε祈祈猫儿з 提交于 2019-12-06 12:01:23
I'm using Mustache 2.7.0 and trying to play with Blocks pragma for the first time. Basically, I call basic.mustache {{< layout }} {{$ title}}{{page.meta.name}}{{/ title}} {{/ layout }} calling the block layout.mustache <!DOCTYPE html> <html> <head></head> <body> <h1>{{$ title}}test{{/ title}}</h1> </body> </html> I see the value of page.meta.name appear on the page, but not the tags written in layout.mustache . Anyone have an idea why? PHP $mustache = new Mustache_Engine(array( 'pragmas' => [Mustache_Engine::PRAGMA_BLOCKS], 'loader' => new Mustache_Loader_FilesystemLoader('htdocs/templates'),