Skip to content

How to pass arguments back to slot content blocks? #1696

Answered by andrewhavens
andrewhavens asked this question in Q&A
Discussion options

You must be logged in to vote

Ahhh! I figured out how to do it. The trick is to use a lambda slot and return the result of calling the block.

class MyFormWrapperComponent.new < ViewComponent::Base
  renders :form_fields, -> (&block) do
    form_fields_content = nil
    form_with(...) do |form|
      form_fields_content = block.call(form)
   end
    form_fields_content
  end
end
<%= form_with(...) do |form| %>
  <% if form_fields? %>
    <%= form_fields %>
  <% end %>
<% end %>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andrewhavens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant