Created
July 6, 2013 21:57
-
-
Save newz2000/5941440 to your computer and use it in GitHub Desktop.
site-wide context variables for Express apps
This file contains 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
// the route is defined | |
app.get('/notices', ensureLoggedIn('/'), routes.notices); | |
// these variables should be available from the template even if not explicitly returned | |
user = getLoggedInUser(); | |
activeNavigation = getCurrentPage(); | |
// some old view | |
exports.notices = function (req, res) { | |
var notices = getNotices(); | |
res.render('pages/notices', {notices: notices}); | |
}; | |
// template should be able to access all three variables | |
<ul class="{{activeNavigation}}"> | |
<li>Homepage</li> | |
<li>Notices</li> | |
<li>Logout {{user.username}}</li> | |
</ul> | |
{{#notices}} | |
<p><strong>{{type}}:</strong> {{text}} | |
{{/notices}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment