Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7971089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:33:39+00:00 2026-06-04T07:33:39+00:00

I began using node.js+express combo very recently and I stumbled at a need to

  • 0

I began using node.js+express combo very recently and I stumbled at a need to use dynamicHelpers not only in my views but also inside my routes setup (routes/index.js in default express config). Should I use some different pattern?

app.js

app.dynamicHelpers({
    translate : function(req, res) {
        return translate;
    },
    language : function(req, res) {
        return req.session.language || "en";
    },
});

Below I would like to have a convenient access to whatever I set for my dynamicHelpers because in my mind it is the same context .. so why set it up two times?

var routes = {};
routes.index = function(req, res) {
    res.render('index', {
        title : 'My webpage',
        categories : categoryPositions,
        referrer : req.header("Referrer"),
        languages : ["pl", "en", "de"],
        <----- here I would like to use my dynamicHelpers (for example translate)
    })
};

I know I can pass my data in many ways but I do not want to repeat my code
and want to set up the common context only once and as cleanly as polssible. I welcome any criticism and good advice!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:33:40+00:00Added an answer on June 4, 2026 at 7:33 am

    So actually the solution is to use not yet released express 3.0, modify:

    npm install -g express@3.0

    Follow https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x , http://www.devthought.com/code/use-jade-blocks-not-layouts/

    The new express simplified dynamicHelpers to the use of res.locals which are both available in the routes setup and then bound to the view.

    Example:

    // app.
    app.locals.use(function(req, res) {
        var language = req.session.language || "en";
        res.locals.language = language;
        res.locals.translate = function(clause) {
            return translate(clause, language);
        };
    });
    

    In the routes setup I can now access both res.locals.language and res.locals.translate.
    In my views I simply can use translate('something').

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Only began using Haskell a couple of weeks ago - I am attempting to
I've recently began using C++ with XCode and I'm starting to miss the integrated
I recently began using github and started playing with eclipse's git abilities, using some
I've recently switched my app over to Rails 3.1 and began using the asset
I began writing an app using declarative_authorization ( http://github.com/stffn/declarative_authorization ) but I'm now wondering
We've been using VSS 6.0 since time began, but yesterday I nabbed VSS2005 off
I've recently came across a very interesting inconsistency while using libxml++ (a C++ wrapper
I am building an app on node.js using express, and node-mysql driver. There is
Must be missing something here, but I'm using Node_redis as Node.js client for Redis.
I just began using Visual Studio to work on a practice .NET project. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.