Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在express中为把手使用.html文件扩展名?_Node.js_Express_Handlebars.js_Template Engine_File Extension - Fatal编程技术网

Node.js 如何在express中为把手使用.html文件扩展名?

Node.js 如何在express中为把手使用.html文件扩展名?,node.js,express,handlebars.js,template-engine,file-extension,Node.js,Express,Handlebars.js,Template Engine,File Extension,所以我想知道如何使用.html扩展名而不是.handlebar或.hbs扩展名。我这样做是为了能够使用常规html进行开发,这样我的前端开发人员就可以无缝地编辑IDE中的文件,而无需任何额外配置。此外,它还将帮助我们更快地将html模板安装到express应用程序中。因此,我可以通过更改app.js文件中的三个内容来实现这一点。我希望这对每个人都有帮助,就像它对我有帮助一样 var express = require('express'), exphbr = require('ex

所以我想知道如何使用.html扩展名而不是.handlebar或.hbs扩展名。我这样做是为了能够使用常规html进行开发,这样我的前端开发人员就可以无缝地编辑IDE中的文件,而无需任何额外配置。此外,它还将帮助我们更快地将html模板安装到express应用程序中。

因此,我可以通过更改app.js文件中的三个内容来实现这一点。我希望这对每个人都有帮助,就像它对我有帮助一样

var express  = require('express'),
    exphbr   = require('express3-handlebars'), // "express3-handlebars"
    helpers  = require('./lib/helpers'),

    app = express(), 
    handlebars;

// Create `ExpressHandlebars` instance with a default layout.
handlebars = exphbr.create({
    defaultLayout: 'main',
    helpers      : helpers,
    extname      : '.html', //set extension to .html so handlebars knows what to look for

    // Uses multiple partials dirs, templates in "shared/templates/" are shared
    // with the client-side of the app (see below).
    partialsDir: [
        'views/shared/',
        'views/partials/'
    ]
});

// Register `hbs` as our view engine using its bound `engine()` function.
// Set html in app.engine and app.set so express knows what extension to look for.
app.engine('html', handlebars.engine);
app.set('view engine', 'html');

// Seperate route.js file
require("./routes")(app, express);

app.listen(3000);

同意杰米洛伊的意见

  • extname:'.myext'
    在创建expr HBS实例(
    exphbr.create()
    )时,根据
  • 将expr HBS引擎绑定到扩展名:
    app.engine('myext',handlebar.engine)根据
  • 将扩展名设置为视图引擎:
    app.set('view engine','myext')-不幸的是,没有链接到它是如何工作的

  • 关于

    您知道如何使用两种类型的扩展名吗?