1

I am attempting the following

A HAML template with

#whitepanelMID
  #groups_view_scroller
    = render 'show' do
      = render 'short_field', locals: {label: 'Name:', value: @group.name}
      = render 'short_field', locals: {label: 'Description:', value: @group.description}

And the partials are _show.html.haml (note the use of yield)

%table#vert_table.no_borders{ cellpadding: '0', cellspacing: '0'}
  %tbody
    %tr
      %td{ cols: 2 } My table
    = yield

and _short_field.html.haml

%tr
  %th.vert_table_heads= label
  %td= value

The issue is that yield does not seem to work.

What's the proper way to use block in render in HAML?

Update

I found a workaround, which I don't like.

In the HAML template capture the output like

#whitepanelMID
  #groups_view_scroller
    - rows = capture_haml do
      = render partial: 'short_field', locals: {field_label: 'Name:', value: @group.name}
      = render partial: 'short_field', locals: {field_label: 'Site:', value: @group.site.description}
    = render partial: 'show', locals:{ content: rows}
    %br/

with the modified partial _show.html.haml with a content variable instead of yield

%table#vert_table.no_borders{ cellpadding: '0', cellspacing: '0'}
  %tbody
    %tr
      %td{ cols: 2 } My table
    != content

Happy to hear a better approach!

carlosayam
  • 1,396
  • 1
  • 10
  • 15

1 Answers1

4

Just because the link provided by @vidaca is ERB, I want to post an equivalent for HAML.

Use layout: when using the wrapper template

#whitepanelMID
  #groups_view_scroller
    = render layout: 'show', locals:{ table_title: 'My table'}
      = render partial: 'short_field', locals: {field_label: 'Name:', value: @group.name}
      = render partial: 'short_field', locals: {field_label: 'Site:', value: @group.site.desccription }        
    %br/

and _show.html.haml partial (wrapper) like

%table#vert_table.no_borders{ cellpadding: '0', cellspacing: '0'}
  %tbody
    %tr
      %td{ cols: 2 }= table_title
    = yield

the wrapped partials (short_field in this case) work as-is.

Hope helps someone.

carlosayam
  • 1,396
  • 1
  • 10
  • 15