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

  • Home
  • SEARCH
  • 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 4036992
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:17:31+00:00 2026-05-20T12:17:31+00:00

I saw someone’s code in View/car.html.haml like followows: %body =yield Can anybody explain me

  • 0

I saw someone’s code in View/car.html.haml like followows:

%body
  =yield

Can anybody explain me the use of “=yield” here?

-where can I find the actual body part code?

-What does it means,

-why use it or in what situation we should use it?

  • 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-20T12:17:32+00:00Added an answer on May 20, 2026 at 12:17 pm

    Typically this will appear in a layout file (by default – views/layouts/application.html.haml). It simply tells Rails to render the content of the current action at that location.

    So if you have views/layouts/application.html.haml with:

    %body
      =yield
    

    And you have views/posts/index.html.haml with:

    %h1 This is the posts index page!  :D
    

    Then when you go to an action that renders the posts index page (probably /posts), you will see the html that has that heading rendered at the location of the yield in your layout file:

    <body>
      <h1>This is the posts index page! :D</h1>
    </body>
    

    This is particularly useful to include things like common page navigation markup, or headers that should show up on all pages without having to re-define the exact html in every view.

    If you have a different layout for a separate section of your site you might render your view in the controller like this:

    def index
      if signed_in?
        render :layout => 'application'
      else
        render 'user/unauthorized', :layout => 'external' and return
      end
    end
    

    Which will use the specified view, rendered inside the specified layout wherever the layout’s yield occurs. In the else of the statement user/unauthorized.html.haml would be rendered within the layouts/external.html.haml layout, and in the signed_in? case you would get the posts/index.html.haml view rendered within the layouts/application.html.haml layout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw someone writing code like this , in a C++ class: int foo
I saw someone's C++ code has function declaration like below: void information_log( const char*
I just saw someone post the following, in a rant on ugly code: public
I recently saw someone with a T-shirt with some Perl code on the back.
Checking the documentation online I saw that it is pass by reference. Can someone
I saw someone load JS in his html as following (via JQuery ajax): (jquery.utils.js,
I saw this code on someone else's website, but found no reference to it
I saw this in some paper and someone argued that there can be at
I was looking at someone's code and saw that he repeatedly declared PrintStream out
In some of my learning I saw someone mention that in your view controller

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.