node.js 模版引擎

模版引擎

一、什么是模版引擎:
模版引擎是为了使用户界面与业务逻辑(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模版引擎就会生成一个标准的文档就是将模版文件和数据通过模版引擎生成一个html文档。
常见的模版引擎: art-template
art-template不仅在能在浏览器使用也可以在node中使用。
二,art-template使用
2.1、安装

npm install art-template
//  该命令在那执行就会把包下载到哪里,默认会下载到node_model目录
// node-model 不要改 也不支持改
<body>
	<script src="node_modules/art-template/lib/template-web.js"></script>
	<script type="text/template" id="tp1">
		大家好,我叫 {{ name }}
		我今年{{ age }} 岁了
		我来自{{ province }}
		我喜欢: {{ each hobbies }} {{ $value }} {{ /each }}
	</script>
	<script>
		var ret = template('tp1', {
			name: 'Jack',
			age: 18,
			province: '北京'
			hobbies: [
				'写代码',
				'打羽毛球'
			]
		})
		console.log(ret)
	</script>
</body>

三、在node.js中使用模板引擎
模板引擎最早诞生于服务器领域,后来才发展到前端
使用步骤:
1、安装 npm install art-template
2、在需要使用的文件模块中加载art-template
只需要使用require方法加载就可以了:

require('art-template')

相关推荐

  1. node.js 模版引擎

    2024-04-22 23:24:02       35 阅读
  2. Nodejs引入模块运行时报错

    2024-04-22 23:24:02       44 阅读
  3. node.js 什么是模板引擎?(具体介绍underscore)

    2024-04-22 23:24:02       37 阅读
  4. Word Excel模版引擎

    2024-04-22 23:24:02       69 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-22 23:24:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-22 23:24:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-22 23:24:02       82 阅读
  4. Python语言-面向对象

    2024-04-22 23:24:02       91 阅读

热门阅读

  1. 报错:Property glob does not exist on type ImportMeta

    2024-04-22 23:24:02       30 阅读
  2. live2d看板娘资源-地址

    2024-04-22 23:24:02       34 阅读
  3. js 数组去重的6种方法

    2024-04-22 23:24:02       33 阅读
  4. LeetCode刷题--- 完全平方数

    2024-04-22 23:24:02       34 阅读
  5. Rust---泛型(Generics)

    2024-04-22 23:24:02       32 阅读
  6. git 代码仓库

    2024-04-22 23:24:02       35 阅读
  7. 如何将本地项目上传到gitlab

    2024-04-22 23:24:02       40 阅读