Dojo template string Best Practices

Source: Internet
Author: User
Tags dot net

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 );
});


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.