question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

locals not accessible within partials

See original GitHub issue

My setup looks something like the following:

var hbs = handlebars.create({
    extname: '.hbs'
});

app.locals['static-server'] = 'https://' + config.services.assets.hostname;

app.set('views', app.path('views'));
app.engine('hbs', hbs.engine);
app.set('view engine', 'hbs');

The static-server local works properly within views, but whenever it is used within a partial, the variable is always undefined. Is this a bug, or do I have something configured incorrectly?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:14

github_iconTop GitHub Comments

8reactions
WeiGrandcommented, Jul 22, 2018

While in a for each loop, {{@root.yourLocalsDataKey}} may help

5reactions
nsafaicommented, Nov 9, 2018

Confirming I experienced the same issue, unable to access a {{user}} (res.locals.user) inside an {{#each array as |item|}}

@WeiGrand 's solution worked for. {{@root.user.name}}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rails partial locals not working - Stack Overflow
Its not a good practice to pass new instance variable as local to a partial you can build the answer and then pass...
Read more >
Partials - Sails.js
Partials only inherit locals that are available to the view, partial, or layout where they're called as a whole, but this <li> relies...
Read more >
ActionView::PartialRenderer - Rails API
The current object being rendered, as well as the object_counter, will be available as local variables inside the layout template under the same...
Read more >
Don't use instance variables in partials - Andy Croll
Instance variables defined in controllers are magically available in view templates. Inferred template names. A global namespace of helpers.
Read more >
Can't access Site variables inside nested partial - HUGO
It might be really simple to solve it but everything I tried failed. I have a nested partial, and I would like to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found