Getting started with the doT js template, dotjs Template

Source: Internet
Author: User

Getting started with the doT js template, dotjs Template

DoT. js github address:
Official website of doT. js
Instance 1: simple

<!DOCTYPE html>

Running result:

Example 2: Condition Determination

<Body> <div id = "conditionstmpl"> {{? ! It. name }}< div> you have no name </div> {{?? }}< Div> Oh, I love your name, {{= it. name }}! </Div> {{?}} </Div> 

Running result:

Example 3: Cycle + condition judgment

<body><div id="evaluationtmpl">    {{ for(var prop in it) { }}        {{? typeof it[prop]=='object' }}            <div style="font-weight: bold;" >KEY:{{= prop }}---VALUE:</div>            {{ for(var prop2 in it[prop]) { }}                <div style="margin-left: 20px;" >key:{{= prop2 }}---value:{{= it[prop][prop2] }}</div>            {{ } }}        {{?? }}            <div>KEY:{{= prop }}---VALUE:{{= it[prop] }}</div>        {{?}}    {{ } }}</div>

Running result:

Source code:
DoT source code and Examples

Note:
1 ,{{? Typeof it [prop] = 'object'} indicates condition judgment. The end tag is {{?}}
2 ,{{?? } Is the else for conditional judgment.
3, {and {{? Can use native js syntax, such as for, typeof, etc.
4. The template does not have to be placed in the script tag, but can also be placed in the hidden div tag.

Author:Huang Wei
Blog address:
CSDN blog homepage
ItEye blog homepage

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.