8000 GitHub - Yacent/Template_Engine: a esay javascript template engine. only for the replace of the variable
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Yacent/Template_Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

##Template Template Engine 小白模板引擎,不喜勿喷呀。

###Principle 基于字符串的前端模板引擎,其原理主要为,将html转为抽象语法树(AST),返回一个函数。 调用函数,并且传入数据model,实现模板数据的渲染,最后,获得节点,将返回字符串以innerHTML的方式嵌入到网页当中

###Usage

####import

<script type="text/javascript" src="template.js"></script>

####HTML Structure

<script id="tpl" type="text/plain">
	<h2>name: {user.name}</h2>
	<p>age: {user.age}</p>
	<p>content: {content}</p>
	<p>That s all</p>
</script>

####Data Model & Trigger

<script type="text/javascript">
	var model = {
		user: {
			name: 'Nick',
			age: 29
		},
		content: 'I am so handsome'
	}

	var tpl = document.getElementById('tpl').innerHTML;
	var content = new Template(tpl);
	document.write(content.render(model));
</script>

About

a esay javascript template engine. only for the replace of the variable

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0