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

Local variables in template are global #3

Closed
apohllo opened this issue Apr 7, 2014 · 4 comments
Closed

Local variables in template are global #3

apohllo opened this issue Apr 7, 2014 · 4 comments
Assignees
Labels

Comments

@apohllo
Copy link

apohllo commented Apr 7, 2014

When there are two templates defined with same local variable, the variable in the called template is shadowed by the variable in the calling template.

E.g.
parent.html.haml

- node.children.each do |child|
  = render template: 'child', locals: { node: child }

child.html.haml

= node.title

In the child template node refers to node in parent template but should refer to child in that template.

@apohllo apohllo changed the title Local variable in template are global Local variables in template are global Apr 7, 2014
@jodosha jodosha self-assigned this Apr 7, 2014
@jodosha jodosha added the bug label Apr 7, 2014
@jodosha
Copy link
Member

jodosha commented Apr 7, 2014

@apohllo Thanks for reporting this.

I assume that child.html.haml is a template and not a partial, because it's missing the leading underscore in the name. The correct way to render a template is to use the :template key. Can you please try with:

= render template: 'nodes/child', locals: { node: child }

@jodosha
Copy link
Member

jodosha commented Apr 7, 2014

@apohllo I can confirm the issue.

@jodosha jodosha closed this as completed in 593f1a5 Apr 7, 2014
@jodosha
Copy link
Member

jodosha commented Apr 7, 2014

@apohllo fixed by 593f1a5

@apohllo
Copy link
Author

apohllo commented Apr 8, 2014

Thanks for this very quick response!

timriley added a commit that referenced this issue Mar 15, 2020
Use a part object as the layout template's scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants