zoukankan      html  css  js  c++  java
  • 在Express中配置使用art-template模板引擎

    先安装需要使用的包

    cnpm install --save art-template
    cnpm install --save express-art-template

    配置(官网案例)

     var express = require('express')
    var express = require('express');
    var app = express();
    //配置使用art-template模板引擎
    //第一个参数表示,当渲染以 .art 结尾时使用art-template模板引擎
    //express-art-templet依赖于art-template 虽然不需要导入,但是必须安装art-template app.engine(
    'html', require('express-art-template')); app.set('view options', { debug: process.env.NODE_ENV !== 'production' }); app.get('/', function (req, res) {
    //express为response对象提供了一个render方法
    //render方法默认是不可用的,需要使用的话必须配置模板引擎
    //参数1:模板名 参数2:模板数据
    //第一个参数不能学路径,默认去项目中的views目录中去找该模板文件
    //如果想要修改默认的views目录 可以 app.set('views',render函数的默认路径)
    //比如 app.set('views','public')那就会去public目录项去找模板文件 res.render(
    'index.html', { user: { name: 'aui', tags: ['art', 'template', 'nodejs'] } }); });

    这是我的404.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>{{user.name}}</title>
    </head>
    <body>
      <h1>抱歉!  您访问的页面失联啦...</h1>
      <div>
        <h1>{{user.name}}</h1>
        <h1>
          {{echo user.tags}}
            <h2>{{ $value }}</h2>
        </h1>
      </div>
    </body>
    </html>

    显示结果为

    抱歉! 您访问的页面失联啦...
    express整合art-template
    art,template,nodejs
  • 相关阅读:
    Bypass WAF
    一种简单的hook方法--LD_PRELOAD变量
    Linux C:access()时间条件竞争漏洞
    环境变量法提权
    sudo-tcpdump提权法
    asynico转载
    pychar 2020.1.2激活
    临时mysql 链接池
    python pip 使用阿里云镜像安装库
    zookeeper kafaka 临时保存
  • 原文地址:https://www.cnblogs.com/a-small-lyf/p/10765885.html
Copyright © 2011-2022 走看看