1

I am trying to render a partial using a named yield. Here's my template

<%= render 'shared/remote_modal', modal_title: "bru" do %>
  <%= content_for(:modal_content) do %>
    <%= render @registrations, show_learner: true, show_product: false %> 
  <% end %>
<% end %>

and here's shared/remote_modal :

<div class="relative px-4 w-full max-w-6xl md:h-auto">
  <!-- Modal content -->
  <div class="relative bg-white rounded-lg shadow dark:bg-gray-700">
    <!-- Modal header -->
    <div class="w-full">
      <div class="flex justify-between items-start p-5 rounded-t">
        <div class="w-full-0">
            <h3 class="text-lg font-semibold text-gray-900 dark:text-white">
              <%= modal_title %>
            </h3>
        </div>
        <i class="close-modal fas fa-times text-lg cursor-pointer"></i>
      </div>
    </div>
    <!-- Modal body -->
    <div class="px-6">
      <div class="w-full">
        <%= yield(:modal_content) %> 
    </div>
  </div>
</div>

As you can see shared/remote_modal has yield(:modal_content) and my template uses content_for(:modal_content). However the block within content_for(:modal_content) is not rendering.

If I change it to a "simple" "unnamed" yield though, it will render properly. Are named yield not supported with partials ? Is there a workaround to this ?

1 Answer 1

0

A possible issue could be that you're using content_for inside the partial, which might not work as expected.

Instead, you can try a different approach (not sure if that's the same you already tried). Try passing the content as a block (without using content_for), and then render this block inside the partial using a simple yield:

<%= render 'shared/remote_modal', modal_title: "bru" do %>
  <%= render @registrations, show_learner: true, show_product: false %> 
<% end %>

Partial:

...
<!-- Modal body -->
<div class="px-6">
  <div class="w-full">
    <%= yield %> 
  </div>
</div>
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.