对象访问的PHP Mustache数组
JSON数据对象访问的PHP Mustache数组,php,mustache,template-engine,mustache.php,Php,Mustache,Template Engine,Mustache.php,JSON数据 { "product_list": [ { "title": "Title Name", } , { "title": "another title" } ] } 胡须模板 {{#product_list}} {{title}} {
{
"product_list": [
{
"title": "Title Name",
}
,
{
"title": "another title"
}
]
}
胡须模板
{{#product_list}}
{{title}}
{{/product_list}}
期待
> Title name
> Another title
但它没有显示任何东西。使用{.}显示产品对象的字符串表示形式。我想在每次迭代中访问对象的属性
更新
public function render()
{
$this->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($templateDir),
'partials_loader' => new \Mustache_Loader_FilesystemLoader($templateDir . DIRECTORY_SEPARATOR .'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],
));
return $this->mustache->render($this->template,$data);
}
更新$data的var_dump()
array (size=2)
'product_list' =>
array (size=2)
0 =>
object(Product)[7]
private 'title' => string 'Title Name' (length=10)
1 =>
object(Product)[7]
private 'title' => string 'another title' (length=13)
@raina77ow请检查更新
var\u dump($data)
show是什么?@raina77ow我已经更新了问题为什么“title”属性显示为私有属性?如何填充这些产品对象?