Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6590357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:17:21+00:00 2026-05-25T17:17:21+00:00

If I have one <%= yield %> tag then all my views render in

  • 0

If I have one <%= yield %> tag then all my views render in the same place in the layout. Can I have different <%= yield %> tags for different views? Is so how do I do this? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:17:21+00:00Added an answer on May 25, 2026 at 5:17 pm

    Look into ActionView::Helpers::CaptureHelper. You can do something like this in your views:

    <% content_for :sidebar do %>
      <!-- sidebar content specific to this page -->
    <% end %>
    

    This will run the template inside the content_for block, but will not output as part of the regular template yield buffer, it will be stored in a separate buffer for later. Then later on, including in the layout, you can use yield :content_name to output the content:

    <div class="content">
        <%= yield %>
    </div>
    
    <div class="sidebar">
        <%= yield :sidebar %>
    </div>
    

    So in a sense you can have different yields for different views, you just have to give the differing content a name with content_for in the views, and yield it with that same name in the layout.

    Consider your case, where you want different views in different places. Let’s say you have three panels, panel1, panel2, and panel3. You can do this in your layout:

    <div id="panel1"><%= yield :panel1 %></div>
    <div id="panel2"><%= yield :panel2 %></div>
    <div id="panel3"><%= yield :panel3 %></div>
    

    You don’t even need to include a plain <%= yield %> if you don’t want to. Then in your views, you can choose which panel to display the content in by surrounding the entire view with the appropriate content_for. For example, one of your views might be changed like this:

    <% content_for :panel2 do %>
        <!-- Your View -->
    <% end %>
    

    To show in panel 2. Another one might be intended for panel 3, like this:

    <% content_for :panel3 do %>
        <!-- Your View -->
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one hibernate sequence, that generates all sequence-numbers in my app. When I
I have one text input and one button (see below). How can I use
I have two threads. First one is something like this: while(1) { pthread_mutex_lock(&mutex); //DO
I have a generator object returned by multiple yield. Preparation to call this generator
If I have two yield return methods with the same signature, the compiler does
This one is sort of twisting my noodle. I have something resembling this (in
I have a lot of code like this in one of my projects (from
I have a function that returns a list via yield. I use this function
I have two different layouts in my app, one for javascript (AJAX) requests and
I have one field that I need to sum lets say named items However

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.