Coming from a Rails/Sinatra background, I won't feel at home without being able to use helper functions in my view files, however achieving this in express.js has proven quite difficult.
You can set locals to be automatically included like this...
app.set("name", "Adam's App");
Then in the view file, accessing the variable is as simple as:
<!-- views/template.ejs -->
<title><%= settings.name %></title>
But what about for functions? What if I want to have a date_helper function in my views? I tried setting it like you would a variable...
app.set("date_helper", function(timestamp){ ... });
...however calling <%= settings.date_helper %> won't execute the function (obviously), let alone enable me to pass the timestamp argument to it.
Am I going about this the right way?
.render('something', { settings: app.settings, helper: function(){...} }, function (err, stuff) {...});along those lines ishsettings: app.settings(I think that's been deprecated in express 3.0?). That aside - my aim here is to have access to these functions without having to specify it in the.renderblock. It seems pretty lame having to usedate_helper: function(){..}in every route I define, agreed?app.locals.date_helperassignment but looks like his is better than what I was gonna say lol