-
Notifications
You must be signed in to change notification settings - Fork 16
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
Clarify how to render the "default content" passed to a partial #29
Comments
In #32 we just added the ability to remove To your question, in #32, we also added <div class="divide-y pb-6">
<div class="flex justify-between items-center">
<legend class="text-2xl font-medium pb-6"><%= legend %></legend>
<% if p.content_for? :actions %>
<%= p.yield :actions %>
<% end %>
</div>
<%= p.output_buffer %>
</div> So I'll close this as fixed for now. |
👏 Thanks for the detailed follow-up! Any thoughts on calling By "supported", I mean that calling |
I just pointed my app to the Here is my (simplified) partial: <div>
<%= p.yield :actions %>
<%= p.output_buffer %>
</div> When I It does work as expected when I use the old style: <% content = yield(p = np) %>
<div>
<%= p.yield :actions %>
<%= content %>
</div> |
I was going to suggest the same method name! I'm in favor of this proposal.
The changes made in #32 hinge on a check on the number of arguments passed to the partial's block: when its arity is one, the block is made available, otherwise, it isn't. I believe the check aims prevent breaking backwards compatibility and tries to avoid disrupting the default partial rendering process with extra or conflicting variables names. |
When called without a `name` argument, treat `Partial#yield` as an `output_buffer` reader. Along with that change, make `output_buffer` a `Partial`-private attribute accessor. bullet-train-co#29 (comment)
Related to [bullet-train-co#29][] When called without a `name` argument, treat `Partial#yield` as an `output_buffer` reader. Along with that change, make `output_buffer` a `Partial`-private attribute accessor. [bullet-train-co#29]: bullet-train-co#29 (comment)
Hm, I'm not quite liking That said, for @seanpdoyle's last example here #27 (comment), it would be interesting if you could do: <%# app/views/application/_form.html.erb %>
<% form_options = local_assigns.slice(:model, :url, :id, :data, :html) %>
<%= form_with some_magic_helper_that_can_deeply_merge_attributes_and_tokens(form_options, data: { controller: "form", action: "submit->form#doSomethingSpecial" }) do |form| %>
<% p.yield form %> <%# <- Call `capture(form, p, &block)` and pass the form along, also passing `p` as the second argument %>
<%= p.yield :controls %>
<div>
<%= link_to "Cancel", :back %>
<%= p.yield :actions %>
</div>
<% end %>
<%# elsewhere %>
<%= render "form", model: @post, data: { controller: "special-form", action: "reset->special-form#resetInASpecialWay" } do |form, builder| %>
<%= builder.controls do %>
<%= form.label :name %>
<%= form.text_field :name %>
<%# ... %>
<% end %>
<%= builder.actions do %>
<%= form.button "Reset", type: "reset" %>
<%= form.button "Submit" %>
<% end %>
<% end %> |
Ok, seeing |
Related to [bullet-train-co#29][] When called without a `name` argument, treat `Partial#yield` as an `output_buffer` reader. Along with that change, make `output_buffer` a `Partial`-private attribute accessor. [bullet-train-co#29]: bullet-train-co#29 (comment) Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
Related to [bullet-train-co#29][] When called without a `name` argument, treat `Partial#yield` as an `output_buffer` reader. Along with that change, make `output_buffer` a `Partial`-private attribute accessor. [bullet-train-co#29]: bullet-train-co#29 (comment) Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
Related to [bullet-train-co#29][] When called without a `name` argument, treat `Partial#yield` as an `output_buffer` reader. Along with that change, make `output_buffer` a `Partial`-private attribute accessor. [bullet-train-co#29]: bullet-train-co#29 (comment) Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
Related to [bullet-train-co#29][] When called without a `name` argument, treat `Partial#yield` as an `output_buffer` reader. Along with that change, make `output_buffer` a `Partial`-private attribute accessor. [bullet-train-co#29]: bullet-train-co#29 (comment) Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
I ran into a bit of confusion integrating Nice Partials into some existing partials that were calling
<%= yield %>
.This raised an error after I added the
p
block variable into the caller becausep
is nil when callingyield
without an argument:The solution (I think) is to capture the result of
yield p = np
and use it instead of callingyield
again:Assuming I'm following the recommended approach here, I think this probably just needs a little documentation in the README.
The text was updated successfully, but these errors were encountered: