Giter VIP home page Giter VIP logo

tpl.js's Introduction

tpl.js

Lightweight javascript template engine. Adaptation AMD, CMD and global environment

Speed Test

Usage

  1. Include tpl.js:
    <script type="text/javascript" src="path/to/tpl.js"></script>

Or in sea.js, you can include by: var tpl = require('path/to/tpl');

  1. Template in your html:
    <script type="text/template" id="demo">
        <p>Hi, I'm <%=author%></p>
        <p>I can write:
        <% for(var i=0; i<languages.length; i++) { %>
        <%=(i===0?"":",")+languages[i]%>
        <%}%>
        </p>
    </script>

Or use internal method echo():

    <script type="text/template" id="demo">
        <p>Hi, I'm <%=author%></p>
        <p>I can write:
        <% 
        for(var i=0; i<languages.length; i++) { 
            echo( (i===0?"":", ") + languages[i] );
        }%>
        </p>
    </script>
  1. Execution rendering:
    console.log( tpl('#demo', {author: "Jony", languages: ["javascript", "php", "shell"]}) );
  1. Result is:
<p>Hi, I'm Jony</p>
<p>I can write: javascript, php, shell</p>

API

tpl(template, data)
tpl(template).render(data)

template can be a html string or '#' plus an id, This will return a rendered html string.

Browser Support

  • IE6+
  • Chrome
  • Safari 4+
  • Firefox 3.5+
  • Opera

Bugs / Contributions

  • Report a bug
  • To contribute or send an idea, github message me or fork the project

Build

tpl.js use UglifyJS2 you should have installed nodejs and run npm install uglify-js -g.

On Windows, you can run build.bat from root directory and it will package tpl.debug.js into tpl.js.

License

tpl.js is available under the terms of the MIT License.

tpl.js's People

Contributors

niceue avatar

Watchers

joker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.