Coder Social home page Coder Social logo

sugartpl's Introduction

sugarTpl 超轻量简单快速的JS模版引擎

  • 简洁的语法,支持嵌套语法
  • 体积超轻量
  • 满足日常所需
  • 编译速度快
  • 麻麻再也不用担心我拼写字符串啦:stuck_out_tongue:

语法

<script type="template/html" id="template">
	//if
	{@if(//todo)
		//code
		${name}
	}@/if}
	
	//for
	{@for(//todo){
		//code
		${age}
	}@/for}
	
	//if else
	{@if(//todo){
		//code
		${handsome}
	}@/if}{@else{
		//code
		${beauty}
	}@/else}
</script>

API

  • sugarTpl(template,argument) 第二个参数用于修改变量表达式默认为${},可以修改为arguments{}
  • sugarTpl(template).compile(json,fn)
//获取当前的模版 <script type="template/html" id="template"></script>的内容
var template = document.getElementById('template').innerHTML;
//获取要渲染模版的位置
var view = document.getElementById('view');
//加载模版
var stpl = sugarTpl(template);
//进行渲染
stpl.compile(json,function(tpl){
	view.innerHTML = tpl;
})
//也可以这样渲染
var tpl = stpl.compile(json);
view.innerHTML = tpl;

DEMO

参考index.html

sugartpl's People

Contributors

seuhkx avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.