zoukankan      html  css  js  c++  java
  • node--express模板引擎

    const express =require('express')
    const path=require('path')
    const template=require('art-template')
    const app =express()
    
    //设置模板引 ,view文件 art后缀
    app.set('view engine','art')
    
    
    //使用express兼容art-template模板引擎
    app.engine('art',require('express-art-template'))
    
    app.get('/list',(req,res)=>{
           let data={
               title:'水果',
               list:['apple','orange','banana']
           }
           //参数一,模板的名称;参数二渲染模板的数据
           res.render('list',data);
    })
    
    app.listen(3000,()=>{
        console.log('running....')
    })
    //在当前目录创建view文件夹
    <!DOCTYPE html>
    <html lang="en">
    <head>
        
        
        
        <meta charset="UTF-8">
        <title>Document</title>
    
    </head>
    <body>
    <div>{{title}}</div>
    <div>
        <ul>
               {{each list}}
                   <li>{{$value}}</li>
               {{/each}}
        </ul>
    </div>
    </body>
    </html>
    
    
    
    ,添加list.art文件
  • 相关阅读:
    MessageFormat理解,MessageFormat.format(Object obj)方法
    正则表达式
    数字处理类
    包装类
    遍历Map的4种方法(来自网络)
    集合类
    数组
    字符串
    语言基础
    Linux下使用openssl加解密
  • 原文地址:https://www.cnblogs.com/hack-ing/p/12114647.html
Copyright © 2011-2022 走看看