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
Multiple "content_for" calls should concatenate #704
Comments
This wouldn’t work out of the box without breaking backwards compatibility, but it could work with a param like <% content_for :head, append: true do %>
<script src="...">
<% end %> vs <% content_for :head, append: false do %>
<script src="...">
<% end %> vs <% content_for :head do %>
<script src="...">
<% end %> (default: replace rather than append) |
Do you think anybody uses the current behaviour of calling content_for twice with the same symbol, which would erase the contents of first call? I find it hard to imagine a use case for that. I think most people simply call it once so the issue never arises, so a warning of the changed behaviour in the upgrade notes would suffice. Of course, if I'm overlooking a way in which the current behaviour might be useful, then adding it as an option would be better. |
It’s not possible to change the current behavior without breaking backwards compatibility, and since Nanoc 4 is so close to a final release, this behavior is not going to change before Nanoc 5.0. |
FYI, I’d certainly welcome a PR that adds the new functionality (in a backwards-compatible way); it’ll end up in Nanoc 4.1 if you do so! |
Ok, I don't mind making a PR, but I really don't like adding a parameter for an option for which no one can think of a use case. I'm fine with using the 1-line monkey patch until the behaviour can change in 5.0 |
I’m OK with a change in behavior in 5.0! |
I would say the current default behaviour is broken so we should remove it. Overwriting content is unexpected and especially confusing because the Rails call of the same name behaves differently. But if there is anyone who can think of a use case for the current behaviour I'm interested to hear it. |
I don't know Rails but well thinking about it I would say I doubt people use the current Since it's a helper and not a core functionality I would say it could be viewed as a bug that should be fixed without waiting for 5.0? |
This behaviour has been around since Nanoc 2.x, and it’s intentional, so calling it a bug and changing the behaviour won’t work. What could be considered a bug is that the current behaviour silently overwrites previous content. I’m OK with a change that makes it raise an exception rather than overwrite content. |
Do you mean you want to change silent overwriting to raise an exception now, and then change it in a future version to concatenate? |
Yes! |
👍 |
So until Nanoc 5.0, we're heading towards an |
For now, I've just added addressed the silent overwriting behaviour in the pull request. Adding an additional parameter temporarily did not seem worth the trouble. |
See #744 for an implementation of |
Currently, when you call
content_for
twice on a page the second call will overwrite the content captured for the first one. It would be more useful if they concatenated, just like the behaviour of content_for in Rails. Consider this example that would be made possible:And somewhere else you could do:
And then put a single
<%= content_for :head %>
in the layout.It would actually be a very simple change in nanoc/helpers/capturing.rb. Just replace line 45 with this:
The text was updated successfully, but these errors were encountered: