Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何动态更改胡须模板数据_Php_Templates_Helper_Mustache - Fatal编程技术网

Php 如何动态更改胡须模板数据

Php 如何动态更改胡须模板数据,php,templates,helper,mustache,Php,Templates,Helper,Mustache,我刚刚开始使用胡子模板引擎。我目前正在使用PHP实现它(https://github.com/bobthecow/mustache.php/wiki). 我使用助手来操作数据的呈现方式 $data = array("name" => "abhilash"); $template = "Hello {{name}}, {{#bold}}Welcome{{/bold}}"; $m = new Mustache_Engine(array( "helpers" => array( "bo

我刚刚开始使用胡子模板引擎。我目前正在使用PHP实现它(https://github.com/bobthecow/mustache.php/wiki). 我使用助手来操作数据的呈现方式

$data = array("name" => "abhilash"); $template = "Hello {{name}}, {{#bold}}Welcome{{/bold}}"; $m = new Mustache_Engine(array( "helpers" => array( "bold" => function($content) { return "<b>$content</b>"; }))); $html = $m->render($template, $data);
这通常不是你使用助手的方式。然而,Mustach基本上需要一个数据源,所以为什么不直接注入它呢

$html = $m->render($template, $dataSource);

嗨,Laurent,我知道这不是为了提供数据源。实际上,我正在尝试构建一个框架(其中mustache负责呈现数据)。在其中,我想添加对模板的支持,以指示数据源模块名称,框架将负责从该数据源收集数据并将其反馈给模板。我认为助手是一种更好的方法,不用修改胡须代码。他告诉你怎么做:)胡须不应该获取数据。数据应该被提取出来并交给Mustach。
$html = $m->render($template, $dataSource);