[英]Dust.js - Render precompiled anonymous template on client side
Is there a way to render a precompiled template that has no name on the client side in DustJs? 有没有办法渲染在DustJs 客户端上没有名称的预编译模板?
Because documentation only shows with a name: 由于文档仅显示名称:
<!-- precompiled templates -->
<script type="text/javascript" src="/lib/templates.js"></script>
<script type="text/javascript">
// The templates are already registered, so we are ready to render!
dust.render('hello', { world: "Saturn" }, function(err, out) {
document.getElementById('output').textContent = out;
})
</script>
It sounds like you would like to load templates by their path after they have been precompiled. 听起来好像您希望在预编译模板后按其路径加载模板。 Dust allows you to do this via AMD (require.js) compatibility.
Dust允许您通过AMD(require.js)兼容性执行此操作。
http://www.dustjs.com/guides/setup/#amd http://www.dustjs.com/guides/setup/#amd
Once you've loaded require.js and set define.amd.dust = true
, you can call dust.render
with the path to a template and Dust will automatically load it for you. 一旦加载了require.js并设置define.amd.dust
define.amd.dust = true
,就可以使用模板的路径调用dust.render
,而Dust会自动为您加载它。
Note that this requires that you compile your templates with the --amd
flag. 请注意,这要求您使用
--amd
标志编译模板。
<script src="r.js"></script>
<script type="text/javascript">
define.amd.dust = true;
require(["lib/dust-full"], function(dust) {
dust.render('path/to/your/template', function(err, out) { ... });
});
</script>
The Dust repository has an example of using AMD to load templates . Dust存储库中有一个使用AMD加载模板的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.