-
Notifications
You must be signed in to change notification settings - Fork 2
Design: Layouts
William Newbery edited this page Sep 15, 2016
·
2 revisions
Layouts using content_for and yield are primarily implemented by those methods in ViewModel.
- When using
Template::render_layout(layout, model, doctype), first the template renders itself via a normalTemplate::render(model, false). - Any blocks passed to
=content_forexecuted by the view model instead of returning the rendered HTML from the block (as would saycontent_tag), instead stores it inside the view model in a map keyed by the contents name and returnsnil(which is rendered as an empty string). - The HTML returned by render is then stored in the view model via
ViewModel::set_main_content. -
Template::render_layoutthen callslayout.renderto render the layout. - When the layout calls the yield function, if it is without a name then the HTML stored by
ViewModel::set_main_contentis returned, or if its called with a symbol, the HTML stored bycontent_forif an entry with that name exists, else an empty string. -
Template::render_layoutthen returns the HTML rendered by the layout.