An example of how to install XTemplate under the project and use it:
1. Install xtpl
The code copy is as follows:
npm install xtpl xtemplate --save
2. Add the test.xtpl file in the views directory, and its content is
this is {{title}}!
4. Integrate into Express, just set the template engine in app.js
var print = require('./routes/print'); //This line of code is placed in the require of app.js declaration code segment. App.set('view engine', 'xtpl'); //This line of code is placed in the app.set code segment of app.use('/ooxx', print); //This line of code is placed in the app.use code segment of app.js5. Test a path
In print.js (router/print.js), the following complete code
var express = require('express');var router = express.Router();router.get('/', function(req, res) {res.render('test', { title: 'Express' });});module.exports = router;6. Start the app.js as follows cmd run as administrator command:
C:/Program Files/nodejs/node_global/microblog>node app.js
7. If you enter in the browser at this time: 127.0.0.1:3000/ooxx
Shown as: this is Express!
The above is an example analysis of the usage method of xtemplate node.js introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!