Search code examples
ruby-on-railshamlrenderpartialyield

Pass HAML content to HAML partial


In Rails/HAML I have the following partial:

.blur
  .blur.underground= text
  .blur.foreground
    = yield

It draws blurred out text in the underground and (should) draw the yielded content in the foreground. Unfortunately, when I call

= render 'partial name' do
  %h1 xyz

the '%h1 xyz' is not inserted in my partial.

Am I doing something wrong or is there an alternative way to achieve this?


Solution

  • This worked for me

    = render layout: 'partial name' do
      %h1 xyz
    

    (note the 'layout') and then

    .blur
      .blur.underground= text
      .blur.foreground
        = yield
    

    produced

    div class="blur">
      <div class="blur underground">text</div>
      <div class="blur foreground">
        <h1>xyz</h1>
      </div>
    </div>