I have used it in the past if I have a partial one that can be called from different pages, which may require contextual content from the page.
The case that I had for the menu. I had my own stock menu items, but then I had yield(:menu) , so that the user loaded the administration page, I could add menu items from the page instead of writing the condition statement in the most partial one.
This is some pseudo code:
_menu.haml
%ul %li Home %li Users %li Roles = yield(:menu)
users.haml
- content_for :menu do %li Add User %li Change permissions
roles.haml
- content_for :menu do %li Add Role
Unlike:
%ul %li Home %li Users %li Roles - if current_controller == 'users' %li Add User %li Change permissions - if current_controller == 'roles' %li Add Role
Although both are functional (if it was real code), I prefer the first method. The second one can get out of hand and get pretty ugly pretty quickly. However, this is a matter of preference.
Geoff lanotte
source share