Ticket #10584: update_layout_docs.diff
| File update_layout_docs.diff, 3.7 kB (added by chuyeow, 7 months ago) |
|---|
-
actionpack/lib/action_controller/layout.rb
old new 29 29 # 30 30 # // The header part of this layout 31 31 # <%= yield %> 32 # // The footer part of this layout -->32 # // The footer part of this layout 33 33 # 34 34 # And then you have content pages that look like this: 35 35 # 36 36 # hello world 37 37 # 38 # Not a word about common structures. At rendering time, the content page is computed and then inserted in the layout, 39 # like this: 38 # At rendering time, the content page is computed and then inserted in the layout, like this: 40 39 # 41 40 # // The header part of this layout 42 41 # hello world 43 # // The footer part of this layout -->42 # // The footer part of this layout 44 43 # 44 # NOTE: The old notation for rendering the view from a layout was to expose the magic <tt>@content_for_layout</tt> instance 45 # variable. The preferred notation now is to use <tt>yield</tt>, as documented above. 46 # 45 47 # == Accessing shared variables 46 48 # 47 49 # Layouts have access to variables specified in the content pages and vice versa. This allows you to have layouts with … … 124 126 # class WeblogController < ActionController::Base 125 127 # layout "weblog_standard" 126 128 # 127 # If no directory is specified for the template name, the template will by default be looked for in +app/views/layouts/+.129 # If no directory is specified for the template name, the template will by default be looked for in <tt>app/views/layouts/</tt>. 128 130 # Otherwise, it will be looked up relative to the template root. 129 131 # 130 132 # == Conditional layouts … … 149 151 # == Using a different layout in the action render call 150 152 # 151 153 # If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above. 152 # Some times you'll have exceptions, though, where one action wants to use a different layout than the rest of the controller. 153 # This is possible using the <tt>render</tt> method. It's just a bit more manual work as you'll have to supply fully 154 # qualified template and layout names as this example shows: 154 # Sometimes you'll have exceptions where one action wants to use a different layout than the rest of the controller. 155 # You can do this by passing a <tt>:layout</tt> option to the <tt>render</tt> call. For example: 155 156 # 156 157 # class WeblogController < ActionController::Base 158 # layout "weblog_standard" 159 # 157 160 # def help 158 # render :action => "help /index", :layout => "help"161 # render :action => "help", :layout => "help" 159 162 # end 160 163 # end 161 164 # 162 # As you can see, you pass the template as the first parameter, the status code as the second ("200" is OK), and the layout 163 # as the third. 164 # 165 # NOTE: The old notation for rendering the view from a layout was to expose the magic <tt>@content_for_layout</tt> instance 166 # variable. The preferred notation now is to use <tt>yield</tt>, as documented above. 165 # This will render the help action with the "help" layout instead of the controller-wide "weblog_standard" layout. 167 166 module ClassMethods 168 # If a layout is specified, all rendered actions will have their result rendered 167 # If a layout is specified, all rendered actions will have their result rendered 169 168 # when the layout <tt>yield</tt>s. This layout can itself depend on instance variables assigned during action 170 169 # performance and have access to them as any normal template would. 171 170 def layout(template_name, conditions = {}, auto = false)