Email: longsu2010 at yeah dot net
I have written an article to introduce the substitute template processing function provided by the dojo/string module. One problem that arises is that it is too troublesome to Write template strings and it involves escaping.
My suggestion is to write the template string in a separate file, and then load it using the dojo/text module (a plug-in of the dojo loader. For more information about the loader plug-in, see the http://blog.csdn.net/tt361/article/details/8125246), which saves the trouble of escape and ensures the separation of js and html. This is also the way the dojo widget template and js program are organized. As for the addition of requests to the server side, after the build is complete, it will be automatically compressed into the corresponding js file.
The procedure is as follows:
The counterfeit template file name is template.html, And the content is
<Div class = "content">
<Div class = "title" >$ {title} </div>
<Div class = "detail" >$ {detail} </div>
<Div class = "info" >$ {info} </div>
</Div> place the hypothetical template.html file in the templates subdirectory as follows:
Require (["dojo/dom", "dojo/string", "dojo/text !. /Templates/template.html "], function (dom, string, template ){
Var article = {title: "", detail: "", info :""};
Dom. byId ("dom-id"). innerHTML = string. substitute (template, article );
});