Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Locals - Every Request
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeff Sheldon  
View profile  
 More options Oct 23 2012, 5:14 pm
From: Jeff Sheldon <nil...@gmail.com>
Date: Tue, 23 Oct 2012 14:14:17 -0700 (PDT)
Local: Tues, Oct 23 2012 5:14 pm
Subject: Locals - Every Request

Sorry if this is a stupid question, still learning.

But is there a way to set a local on every request?  For variables in the
Layouts (in the case of jade)

I'm trying:

app.use(function (req, res, next) {
    res.set({ someValue: "1" });
    next();});

But I still get a reference error within the view.  Am I just doing this wrong? Or is this not possible?

-Jeff


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
greelgorke  
View profile  
 More options Oct 24 2012, 3:52 am
From: greelgorke <greelgo...@gmail.com>
Date: Wed, 24 Oct 2012 00:52:56 -0700 (PDT)
Local: Wed, Oct 24 2012 3:52 am
Subject: Re: Locals - Every Request

with res.set you set Header fields.

what you want is res.locals or app.locals

http://expressjs.com/api.html#res.locals

greets

Am Dienstag, 23. Oktober 2012 23:14:17 UTC+2 schrieb Jeff Sheldon:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Sheldon  
View profile  
 More options Oct 24 2012, 9:21 am
From: Jeff Sheldon <nil...@gmail.com>
Date: Wed, 24 Oct 2012 06:21:08 -0700 (PDT)
Local: Wed, Oct 24 2012 9:21 am
Subject: Re: Locals - Every Request

I thought I'd tried that previously.

So towards the top I have:

app.use(function (req, res, next) {
    res.locals.currentTime = new Date();
    next();});

app.get('/', routes.index);

Then in routes.index I have:

exports.index = function (req, res) {
    res.render('index');

/*

    I *did* have the following, which I thought was causing the problem.

    res.render('index', { title: "Welcome" });

*/};

And in my view I simply have

=currentTime

But I still get the following reference error that currentTime is undefined:

currentTime is not defined
at eval (eval at (.....\node_modules\jade\lib\jade.js:176:8))
at Object.exports.compile (.....\node_modules\jade\lib\jade.js:181:12)
at ServerResponse.res._render (....\node_modules\express\lib\view.js:425:23)
at ServerResponse.res.render (....\node_modules\express\lib\view.js:318:17)
at exports.index (....\routes\index.js:7:9)
at callbacks (....\node_modules\express\lib\router\index.js:272:11)
at param (....\node_modules\express\lib\router\index.js:246:11)
at pass (....\node_modules\express\lib\router\index.js:253:5)
at Router._dispatch (....\node_modules\express\lib\router\index.js:280:5)
at Object.middleware [as handle] (....\node_modules\express\lib\router\index.js:45:10)

I appreciate the help.
-Jeff


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Sheldon  
View profile  
 More options Oct 24 2012, 11:38 am
From: Jeff Sheldon <nil...@gmail.com>
Date: Wed, 24 Oct 2012 08:38:51 -0700 (PDT)
Local: Wed, Oct 24 2012 11:38 am
Subject: Re: Locals - Every Request

Actually, I got it to work by doing this:

app.use(function (req, res, next) {
    res._locals = {
        currentTime: new Date()
        };
    next();});

Is that a completely wrong way to handle this?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »