简体   繁体   English

Dust.js外部模板

[英]Dust.js external template

I am new to Dust.js and I have just gone thru "the only" complete tutorial I am able to find on the internet ( https://github.com/linkedin/dustjs/wiki/Dust-Tutorial ). 我是Dust.js的新手,我刚刚通过了“唯一的”完整教程,可以在Internet上找到它( https://github.com/linkedin/dustjs/wiki/Dust-Tutorial )。 Now, I have some understanding on it, try to experiment around to get better understanding. 现在,我对此有了一些理解,请尝试进行试验以获得更好的理解。

From my understanding, we can put the template on the main page so it will look something like this: 据我了解,我们可以将模板放在主页上,使其看起来像这样:

<script type="text/x-template" id="itemTemplate">
    {company}
    {#employees}
       <div> Name: {name}</div>
    {/employees}
</script>

I tried putting the content into mytemplate.tl and load it from script. 我尝试将内容放入mytemplate.tl并从脚本加载它。

<script type="text/x-template" id="itemTemplate" src="template/mytemplate.tl"></script>

But it did work. 但这确实有效。 How can I put that template externally? 如何将模板放在外部?

Thank you. 谢谢。

There is a pretty decent example here: Basic Example of Client Side Templating with Dust.js . 这里有一个相当不错的示例: 使用Dust.js进行客户端模板化的基本示例 Ideally you would compile the template to JS before sending it to the client as that would be faster on the client-side but for playing around, compiling it on the client is easier. 理想情况下,您可以在将模板发送给客户端之前先将其编译为JS,因为这在客户端上会更快,但要想玩起来,在客户端上编译会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM