目前我在客户端javascript中做了dustjs如下
<!DOCTYPE html>
<html>
<head>
<script src="lib/dust-full-0.3.0.min.js" type="text/javascript"></script>
<script src="vendor/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
// JSON response from server
var json_object = { "profile_skill": "Profile Skill",
"skills": [
{ "name": "JavaScript" },
{ "name": "Ruby" },
{ "name": "Java" }
]
}
// render method
dustRender = function(){
// Get the dust html template to dust compile
var dust_tag = $('#page').html() ;
var compiled = dust.compile(dust_tag, "tmp_skill");
//load templates
dust.loadSource(compiled);
//Renders the named template and calls callback on completion. context may be a plain object or an instance of dust.Context.
dust.render("tmp_skill", json_object, function(err, html_out) {
//HTML output
$('#page').html(html_out);
console.log(html_out);
});
}();
});
</script>
</head>
<body>
<h1>Dust templates in the browser</h1>
<div id="page">
{profile_skill}
<ul> {#skills}
<li> {name} </li>
{/skills}
</ul>
</div>
</body>
</html>
但是在我的页面视图源中,我可以看到上面的代码而不是 html 标记输出。而且我还想知道如何将dustjs集成到php代码中。