Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings locals variables on a partial no longer works #454

Closed
nick opened this issue Oct 22, 2010 · 10 comments
Closed

settings locals variables on a partial no longer works #454

nick opened this issue Oct 22, 2010 · 10 comments

Comments

@nick
Copy link
Contributor

nick commented Oct 22, 2010

I just updated from tag 1.0.0rc4 and my partials no longer work properly. Example partial:

!= partial('restaurants/_restaurant_js.html.ejs', {locals: {restaurant: restaurant.data}})

In the partial, I can't access any properties of the 'restaurant' variable. But it worked fine before the upgrade. It looks like locals are no longer being set properly

@tj
Copy link
Member

tj commented Oct 22, 2010

shit, im on it

@tj
Copy link
Member

tj commented Oct 22, 2010

seems fine actually ...

I just noticed you have .html.ejs, what version of express did you have before? things have changed a bit, check out http://expressjs.com/migrate.html

@nick
Copy link
Contributor Author

nick commented Oct 26, 2010

I checked again - it works fine for strings and numbers, but I can't seem to access sub properties of objects. So in my case, if restaurant.data = "ok", that works, but if it's {_id: "chutneys"}, I can't access restaurant._id in the partial.

@tj
Copy link
Member

tj commented Oct 26, 2010

:s weird wtf

@tj
Copy link
Member

tj commented Oct 26, 2010

this test should confirm that what you are mentioning is fine...

    'test #partial() locals': function(assert){
    var app = create();

    app.get('/', function(req, res, next){
        res.send(res.partial('pet-count.jade', {
          partial: true,
          layout: false,
          locals: {
            pets: {
              length: 5
            }
          }
        }));
    });

    assert.response(app,
        { url: '/' },
        { body: 'We have 5 cool pets\n' });
},

so im not to sure :s

@nick
Copy link
Contributor Author

nick commented Oct 26, 2010

OK, the reason was because I have a variable called 'restaurant' in my main view and a different on in the partial. This used to work but a recent change means local variables in a partial get overwritten if there is a variable with the same name in the main view

@tj
Copy link
Member

tj commented Oct 26, 2010

ah i see. that makes sense. I should swap the precedence then

@nick
Copy link
Contributor Author

nick commented Oct 26, 2010

cheers, sorry for the confusion. Was a weird looking bug, heh

@tj
Copy link
Member

tj commented Oct 26, 2010

Fixed partial local inheritance precedence. Closed by 33136c6

@tj
Copy link
Member

tj commented Oct 26, 2010

no no, thanks man, it seemed like a non-issue at first, but definitely a good catch

rauchg pushed a commit to rauchg/express that referenced this issue Sep 25, 2011
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants