ahjesはnodejsにdotjsテンプレートをサポートさせます.

1904 ワード

数日間の実験と捜索を経て,やっと中間部品がこの問題を解決できることがわかった.
npm install consolidate
 
consolidateコンベヤー?ドア トランスポートゲート2    コンベヤー?ドア

:ahjesus
Since doT(and probably your template engine of chece、as well)is accessed through consolidte、consolidate is the only module I need to require at the top of server.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 configration stuff below the existing  app.use ライン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ラインset doT(as exposed by consolidte)as the view engine,register files ending  .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" ト  /public/tmpl/detail.dot and render it as a doT template.Now I can retart my server,go tohttp://localhost:3000/product/102and see my template rended statically、without creating a separate server-side file.