模板引擎

模板引擎 起到 数据和视图分离的作用, 模板对应视图, 关注如何展示数据, 在模板外头准备的数据, 关注那些数据可以被展示。

后端模板引擎

freemarker

如下介绍,  java后台的模板引擎, freemark介绍,其图能很好标明这种关系。

http://freemarker.org/

Apache FreeMarker is a template engine: a Java library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data. Templates are written in the FreeMarker Template Language (FTL), which is a simple, specialized language (not a full-blown programming language like PHP). You meant to prepare the data to display in a real programming language, like issue database queries and do business calculations, and then the template displays that already prepared data. In the template you are focusing on how to present the data, and outside the template you are focusing on what data to present.

velocity

另外一个 java模板引擎, velocity:

http://velocity.apache.org/

velocity是一个基于java的模板引擎, 它允许任何人使用简单但是强大的 模板语言, 引用 java代码中的对象。

Velocity is a Java-based template engine. It permits anyone to use a simple yet powerful template language to reference objects defined in Java code.

按照MVC的思想分离任务, web页面开发者关注如何将页面做的好看, 业务开发者关注写首要的逻辑代码。

其对 JSP代码是一种取代。

When Velocity is used for web development, Web designers can work in parallel with Java programmers to develop web sites according to the Model-View-Controller (MVC) model, meaning that web page designers can focus solely on creating a site that looks good, and programmers can focus solely on writing top-notch code. Velocity separates Java code from the web pages, making the web site more maintainable over its lifespan and providing a viable alternative to Java Server Pages (JSPs) or PHP.

不仅仅可以做HTML模板, 也可以做XML和sql其它重复性代码生成工具。

Velocity’s capabilities reach well beyond the realm of the web; for example, it can be used to generate SQL, PostScript and XML from templates.

前端模板引擎

随着前端技术发展, 和前端处理能力增强, 越来越多的 渲染逻辑在浏览器端实现, 由此出现前端模板引擎, 仿照后台模板引擎方法, 定义前端模板语言, 实现前端模板引擎。

arttemplate

https://github.com/aui/artTemplate

新一代 javascript 模板引擎

编写模板

使用一个type="text/html"script标签存放模板:

  1. <script id=“test” type=“text/html”>
  2. <h1>{{title}}</h1>
  3. <ul>
  4. {{each list as value i}}
  5. <li>索引 {{i + 1}} :{{value}}</li>
  6. {{/each}}
  7. </ul>
  8. </script>
渲染模板
  1. var data = {
  2. title: '标签',
  3. list: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他']
  4. };
  5. var html = template('test', data);
  6. document.getElementById('content').innerHTML = html;

演示

示例:  http://aui.github.io/artTemplate/demo/basic.html

arttemplate 性能介绍

http://cdc.tencent.com/2012/06/15/%e9%ab%98%e6%80%a7%e8%83%bdjavascript%e6%a8%a1%e6%9d%bf%e5%bc%95%e6%93%8e%e5%8e%9f%e7%90%86%e8%a7%a3%e6%9e%90/

artTemplate 介绍

artTemplate 是新一代 javascript 模板引擎,它采用预编译方式让性能有了质的飞跃,并且充分利用 javascript 引擎特性,使得其性能无论在前端还是后端都有极其出色的表现。在 chrome 下渲染效率测试中分别是知名引擎 Mustache 与 micro tmpl 的 25 、 32 倍。

art-template结合tomjs编译工具效果更佳

https://github.com/aui/tmodjs/

如果在页面中维护很多 <script>模板端段, 则会很庞大, 且解析效率不佳:

此工具允许各个模板独自文件管理, 然后精怪此工具合并压缩, 成为一个可引用的模板文件:

使用默认的格式

TmodJS 默认将整个目录的模板压缩打包到一个名为 template.js 的脚本中,可直接在页面中使用它:

  1. <script src="tpl/build/template.js"></script>
  2. <script>
  3. var html = template('news/list', _list);
  4. document.getElementById('list').innerHTML = html;
  5. </script>

template.js 还支持 RequireJS、SeaJS、NodeJS 加载。示例

指定格式(amd / cmd / commonjs)

此时每个模板就是一个单独的模块,无需引用 template.js:

  1. var render = require('./tpl/build/news/list');
  2. var html = render(_list);

jquery template模板引擎

http://www.cnblogs.com/FoundationSoft/archive/2010/05/19/1739257.html

http://www.cnblogs.com/whitewolf/archive/2011/10/09/2204185.html

https://github.com/BorisMoore/jquery-tmpl

    <!DOCTYPE html><html><head><script src="http://code.jquery.com/jquery-latest.min.js"></script><script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script></head><body><ul id="movieList"></ul><script>var movies = [{ Name: "The Red Violin", ReleaseYear: "1998" },{ Name: "Eyes Wide Shut", ReleaseYear: "1999" },{ Name: "The Inheritance", ReleaseYear: "1976" }];var markup = "<li><b>${Name}&lt;/b&gt; (${ReleaseYear})</li>";/* Compile the markup as a named template */$.template( "movieTemplate", markup );/* Render the template with the movies data and insertthe rendered HTML under the "movieList" element */$.tmpl( "movieTemplate", movies ).appendTo( "#movieList" );</script></body></html>

        </div></div>

前端与后端的模板引擎相关推荐

  1. MVT模型<->前后端不分离前后端分离模板引擎

    一.前后端不分离与前后端分离的比较 前后端不分离特点: 后端需控制数据的展示 前后端不分家,耦合严重 返回的是HTML页面,适应性.拓展性差 只能用于浏览器,其它终端不匹配 前后端分离的特点: 当前主 ...

  2. 前后端交互—模板引擎的使用 过滤器的制作及使用 简易的template制作

    模板引擎的逛网首页及下载使用  template. http://aui.github.io/art-template/zh-cn/docs/ 一.模板引擎的使用 引用, 定义模板 .渲染数据.调用t ...

  3. 前端进击笔记第十二节 掌握前端框架模板引擎的实现原理

    如今说起前端开发,基本上都离不开前端框架.随着前端技术不断迭代,前端框架相关的文档和社区日益完善,前端入门也越来越简单了.我们可以快速上手一些工具和框架,但常常会忽略其中的设计和原理. 对框架和工具的 ...

  4. LayUI模板引擎渲染数据

    前端模板引擎介绍 接上节Spring boot项目开发实战--(LayUI实现前后端数据交换与定义方法渲染数据) 模板引擎能简化开发,极大提高效率,小编之前使用过JSP和Thymeleaf,以及pyt ...

  5. ThinkPHP6 模板引擎普通标签中,模板引擎运算符函数,循环标签,判断标签的使用,及一些特殊标签

    ThinkPHP6 模板引擎普通标签中,模板引擎运算符函数,循环标签,判断标签的使用,及一些特殊标签 模板引擎支持普通标签和XML标签方式两种标签定义,分别用于不同的目的: 标签类型 描述 普通标签 ...

  6. Transphporm-另一种模板引擎

    If there is one thing the world needs, it's definitely another PHP template engine! But wait, this o ...

  7. 模板引擎的发展 及 thymeleaf

    一.模板引擎的发展 1.后端模板渲染 前端与后端最初的渲染方式是后端模板渲染,就是由后端使用模板引擎渲染好 html 后,返回给前端,前端再用 js 去操作 dom 或者渲染其他动态的部分. 这个过程 ...

  8. 模板引擎Beet的6大创新点

    为什么80%的码农都做不了架构师?>>>    2011年发布Beetl 0.5的时候,新闻是在Iteye上发布的,老资格程序员可能预料Iteye上会发生什么了,我收到的最多的不是鼓 ...

  9. Vert.x - SpringBoot 整合 vertx 使用 thymeleaf、freemarker 模板引擎

    一.模板引擎 在 SpringMVC 项目中使用模板引擎,使用较多的应该是 thymeleaf 及 freemarker 了吧,虽然现在前后端分离的浪潮已经席卷而来,但对于 SEO 或者 页面静态话来 ...

最新文章

  1. 有的放矢,远程操控中实时音视频的优化之道
  2. 第四章 分治策略 4.1 最大子数组问题 (暴力求解算法)
  3. 矩阵的Cholesky分解
  4. Ubuntu-安装MySQL5.7并配置用户名密码
  5. 可变参数函数的一个简单例子
  6. r.java自动删除变量_比较变量并删除一个最低值R [关闭]
  7. jquery,6位密码输入框效果
  8. 微信小程序微商城(六):动态API实现新品特卖商品流式布局
  9. 真核有参转录组测序标准分析-2
  10. C语言之位操作和整形的补位
  11. matlab 二维矩形函数,科学网—利用MATLAB对非矩形域实现二维插值 - 张乐乐的博文...
  12. Mac与Windows操作系统的区别
  13. 领跑全球安全行业,为什么是以色列?
  14. 如何做一个简单的APP
  15. 杨辉三角的c语言代码,杨辉三角C语言代码
  16. ModuleNotFoundError: No module named ‘pip‘;ERROR: Could not find a version that satisfies the requir
  17. 业务高速增长场景下的稳定性建设实战
  18. 图像处理与模式书籍推荐
  19. vscode c++不能使用bits/stdc++.h 解决方案
  20. Kafka中的这只“千里眼”,你需要知道,java常用框架面试

热门文章

  1. MSVCR110.dll缺失问题解决
  2. 刘鹏老师和王超老师的计算广告第二版读书笔记
  3. 聚客网络6元撸一年景安空间
  4. mysql连接与嵌套查询_数据库的连接查询和嵌套查询怎么做啊?
  5. System Requirements
  6. c++分割字符串split方法实现
  7. Activity面试题库
  8. 自动驾驶创业公司首家:小马智行拿下北京无人路测牌照
  9. 欧洲最大IT展会CeBIT开幕 绿色IT是主题
  10. android下赚钱的几个方式