JavaScript 模板引擎 tpl.js

码农软件 · 软件分类 · 模板引擎 · 2019-08-23 16:28:29

软件介绍

一个轻量的(仅1kb),极速的javascript 模板引擎。

 支持预编译,支持嵌入原生javascript语法,忽略不存在的变量,可直接在AMD、CMD以及全局环境中使用。

使用方法:

1.引入tpl.js

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

或者在Sea.js和Node.js中:

var tpl = require('path/to/tpl');

2.HTML模板

<div id="view"></div>

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

3.执行渲染

console.log( tpl('#demo', {author: "Jony", languages:["javascript", "php", "shell"]}) );

 结果为: 

<p>Hi, I'm Jony</p>
<p>I can write: javascript, php, shell</p>

 

在线例子:http://niceue.github.io/tpl.js/

在线文档:https://github.com/niceue/tpl.js 

本文地址:https://codercto.com/soft/d/13006.html

Foundation Web Standards

Foundation Web Standards

Jonathan Lane、Steve Smith / Friends of ED / 21st July 2008 / $34.99

Foundation Web Standards explores the process of constructing a web site from start to finish. There is more to the process than just knowing HTML! Designers and developers must follow a proper proces......一起来看看 《Foundation Web Standards》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

随机密码生成器
随机密码生成器

多种字符组合密码

SHA 加密
SHA 加密

SHA 加密工具