Created
April 19, 2011 11:12
-
-
Save aseemk/927144 to your computer and use it in GitHub Desktop.
Express sample app using Eco templating engine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express.createServer(); | |
app.configure(function () { | |
app.use(app.router); | |
}); | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'html'); | |
app.register('.html', require('eco')); | |
app.get('/', function (req, res) { | |
res.render('test', { foo: 'bar' }); | |
}); | |
app.listen(8080); | |
console.log('listening on port 8080...'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% layout('layout_site') %> | |
<h2>Main Layout</h2> | |
<p> | |
This is the main page layout. | |
It is wrapped by the <t>layout_site</t> layout. | |
</p> | |
<%- body %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<head> | |
<meta charset=utf-8> | |
<title>Nested Layouts Demo</title> | |
</head> | |
<body> | |
<h1>Site Layout</h1> | |
<p> | |
This is the master site layout. | |
It is not wrapped by a layout. | |
</p> | |
<%- body %> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% layout('layout_main') %> | |
<h3>Index Page</h3> | |
<p> | |
This is the main page content. | |
It is wrapped by the <t>layout_main</t> layout. | |
</p> |
When I run this on Express 2.2.2, I get this error:
TypeError: Object module.exports = function(__obj) {
var _safe = function(value) {
if (typeof value === 'undefined' && value == null)
value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
};
return (function() {
var __out = [], __self = this, _print = function(value) {
if (typeof value !== 'undefined' && value != null)
__out.push(value.ecoSafe ? value : __self.escape(value));
}, _capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return _safe(result);
};
(function() {
layout('layout_main');
_print(_safe('\n\n<h3>Index Page</h3>\n<p>\n This is the main page content. \n It is wrapped by the <t>layout_main</t> layout.\n</p>'));
}).call(this);
return __out.join('');
}).call((function() {
var obj = {
escape: function(value) {
return ('' + value)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"');
},
safe: _safe
}, key;
for (key in __obj) obj[key] = __obj[key];
return obj;
})());
}; has no method 'call'
at ServerResponse._render (/usr/lib/node/.npm/express/2.2.2/package/lib/view.js:377:21)
at ServerResponse.render (/usr/lib/node/.npm/express/2.2.2/package/lib/view.js:242:17)
at Object.<anonymous> (/Users/aseemk/Projects/Node/eco-test/app.js:13:9)
at param (/usr/lib/node/.npm/connect/1.3.0/package/lib/middleware/router.js:148:21)
at pass (/usr/lib/node/.npm/connect/1.3.0/package/lib/middleware/router.js:164:10)
at Object.router [as handle] (/usr/lib/node/.npm/connect/1.3.0/package/lib/middleware/router.js:170:6)
at next (/usr/lib/node/.npm/connect/1.3.0/package/lib/http.js:204:15)
at Object.handle (/usr/lib/node/.npm/express/2.2.2/package/lib/http.js:75:5)
at next (/usr/lib/node/.npm/connect/1.3.0/package/lib/http.js:204:15)
at HTTPServer.handle (/usr/lib/node/.npm/connect/1.3.0/package/lib/http.js:217:3)
But if I tweak require('eco')
to require('ejs')
, it works as expected.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that the three .html files should be under a views directory. Gist doesn't allow full paths as filenames.