-
Notifications
You must be signed in to change notification settings - Fork 144
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
Locals aren't rendered in the layout (render plugin) #80
Comments
This is the expected and specified behavior. You need to pass layout options via I suppose we could consider an option (off by default) to the render plugin that would automatically merge the view template :locals into the layout template :locals. I can probably work on that before the next release. |
Cool. It is somewhat confusing if you're coming from sinatra or something similiar where the passed variables are available in both the layout and the template. My specific use case is to have the same value in the I saw the |
I can definitely see where it can cause issues. It's not a problem if you pass data to the view implicitly via instance variables (like sinatra, view scope is the same as route scope), but some people prefer the more explicit approach by specifying locals. I'll improve the docs as well, but I do think it would be good to support using :locals for both the view template and layout template via an option. |
How about |
That's basically what the option would do. It can't be the default behavior (at least not till Roda 3), as it would affect backwards compatibility. With this option, here is how I'm planning to populate locals, in terms of priority (least to greatest):
|
Sounds great. |
Thanx! Further to this, I see that the locals passed to a template / layout aren't inherited by partials either. Is this intentional, or an omission? The workaround is to obviously pass the locals to the partial call:
|
That is intentional. Note that templates are cached per combination of locals, so just blinding merging locals into partials could lead to increased memory usage (possibly combinatoric memory usage in edge cases with nested partials). You could probably use the view_options plugin, which allows you to set locals in one place and use them for all template renders. |
Cool, thanx, looks useful. |
Given the following app:
The outcome is:
Instead of
The text was updated successfully, but these errors were encountered: