Skip to content

fh332393900/light-tpl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

light-tpl

NPM version License MIT NPM size NPM downloads

🍋 🍊 🍒 🍰 🍇 🍉 🍓 🌽 🍑 🍈

How to use

You can install using npm

npm i light-tpl

Output the template as a function return value

    let tpl = require('light-tpl')
    export default function myTest() {
        let data = [
            {name:"fenghang",phone:"15900001111",age:21},
            {name:"222",phone:"110",age:50}]
        let template = `
            <ul>
                <% for(var i=0; i < data.length; i++){
                    var item = data[i];
                    if(item.age < 30){%>
                        <li>我的名字是<%=item.name%>,我的年龄是<%=item.age%>,我的手机号:<%=item.phone%></li>
                    <%}else{%>
                        <li>my name is <%=item.name%>,my age is a sercet.</li>
                    <%}%>
                <% } %>
            </ul>`
        return tpl(template,data)
    }

result:

        <ul>  
            <li>我的名字是fenghang,我的年龄是21,我的手机号:15900001111</li>
            <li>my name is 222,my age is a sercet.</li>
        </ul>

Rendered HTML:

  • 我的名字是fenghang,我的年龄是21,我的手机号:15900001111
  • my name is 222,my age is a sercet.

About

A lightweight JavaScript template engine:lemon: :tangerine: :cherries: :cake: :grapes: :watermelon: :strawberry: :corn: :peach: :melon:

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published