I have a few common UI-components, which varies only by content. Consider this example:
.component
.top
// a lot of component code
.the_actual_top_content
// some more component code
.bottom
// component code
.the_actual_bottom_content
// and more component code
I wonder is there any way to pass content blocks of haml code to function, which will wrap these blocks in my custom UI-component? Something like this:
= component
<<
.the_actual_top_content
<<
.the_actual_bottom_content
Or like this:
= render :layout => 'component' do
= content_for :top do
.the actual_top_content
= content_for :bottom do
.the_actualy_bottom_content
One way to do this is defining helper functions for your UI components. For example, create this helper method in
ApplicationHelper:And then in your HAML template do this:
This will render:
Edit:
Found a better solution, use
render :layout:Here is a partial called
_ui.html.haml:Which is called like this:
Which wil render the same HTML as above.
Edit 2
Although far from ideal, here is a way to do what you are asking:
Here is a partial called
_ui2.html.haml:Which is called like this:
I’ve tried to place the
captureblocks on the render line, but that doesn’t work with properly with HAML indentation.