zoukankan      html  css  js  c++  java
  • ahjesus让nodejs支持dotjs模板

    经过几天的实验加搜索,终于知道一个中间件可以解决这个问题了

    npm install consolidate
    consolidate传送门 传送门2

    使用说明传送门

    快照:ahjesus

    Since doT (and probably your template engine of choice, as well) is accessed through consolidate, consolidate is the only additional module I need to require at the top ofserver.js:

    var express = require( "express" ),
    	app = express(),
    	cons = require( "consolidate" );

    I want to continue serving some of my other pages statically, so I add my template configuration stuff below the existing app.use line in my code:

    app.use( express.static( _dirname + "/public" ) );
    app.engine( "dot", cons.dot );
    app.set( "view engine", "dot" );
    app.set( "views", _dirname + "/public/views" );

    Those three new lines set doT (as exposed by consolidate) as the view engine, register files ending in .dot as templates, and tell Express to look in /public/tmpl for templates to use. So when Node sees res.render( "detail", { ... } ), it knows to expand"detail" to /public/tmpl/detail.dot and render it as a doT template. Now I can restart my server, go to http://localhost:3000/product/102, and see my template rendered statically, without creating a separate server-side file.

  • 相关阅读:
    每日一题20180325
    Linux下MySQL表名区分大小写
    CentOS删除编译安装的Python3
    HTTPS配置
    测试 js 方法运行时间(转)
    使用dbutils进行批处理
    oracle生成主键
    JDBC学习笔记(10)——调用函数&存储过程(转)
    easyui Draggable
    blob
  • 原文地址:https://www.cnblogs.com/ahjesus/p/3722409.html
Copyright © 2011-2022 走看看