Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8471

Show
Ignore:
Timestamp:
12/21/07 12:30:29 (5 months ago)
Author:
bitsweat
Message:

Update layout docs. Closes #10584 [Cheah Chu Yeow]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/layout.rb

    r8378 r8471  
    3030    #   // The header part of this layout 
    3131    #   <%= yield %> 
    32     #   // The footer part of this layout --> 
     32    #   // The footer part of this layout 
    3333    # 
    3434    # And then you have content pages that look like this: 
     
    3636    #    hello world 
    3737    # 
    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: 
    4039    # 
    4140    #   // The header part of this layout 
    4241    #   hello world 
    43     #   // The footer part of this layout --> 
     42    #   // The footer part of this layout 
     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. 
    4446    # 
    4547    # == Accessing shared variables 
     
    125127    #     layout "weblog_standard" 
    126128    # 
    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>. 
    128130    # Otherwise, it will be looked up relative to the template root. 
    129131    # 
     
    150152    #  
    151153    # 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: 
    155     # 
    156     #   class WeblogController < ActionController::Base 
     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: 
     156    # 
     157    #   class WeblogController < ActionController::Base 
     158    #     layout "weblog_standard" 
     159    # 
    157160    #     def help 
    158     #       render :action => "help/index", :layout => "help" 
     161    #       render :action => "help", :layout => "help" 
    159162    #     end 
    160163    #   end 
    161164    # 
    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. 
    167166    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 
    169168      # when the layout <tt>yield</tt>s. This layout can itself depend on instance variables assigned during action 
    170169      # performance and have access to them as any normal template would.