diff options
author | Marcel Molina <marcel@vernix.org> | 2006-04-25 04:03:51 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2006-04-25 04:03:51 +0000 |
commit | 7bb20659c295d2b6a2820295b948ae3a2c0fa99e (patch) | |
tree | c719fba93498776b64cc54aabadcffa0e7b8a082 /actionpack/lib/action_view | |
parent | 51cd1aec00c182c6789f09f9bf40365934034bcd (diff) | |
download | rails-7bb20659c295d2b6a2820295b948ae3a2c0fa99e.tar.gz rails-7bb20659c295d2b6a2820295b948ae3a2c0fa99e.tar.bz2 rails-7bb20659c295d2b6a2820295b948ae3a2c0fa99e.zip |
Update layout and content_for documentation to use yield rather than magic @content_for instance variables.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4262 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/capture_helper.rb | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 9828fe0fa2..8dadf21865 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -1,6 +1,6 @@ module ActionView module Helpers - # Capture lets you extract parts of code into instance variables which + # Capture lets you extract parts of code which # can be used in other points of the template or even layout file. # # == Capturing a block into an instance variable @@ -8,12 +8,11 @@ module ActionView # <% @script = capture do %> # [some html...] # <% end %> - # # # == Add javascript to header using content_for # - # content_for("name") is a wrapper for capture which will store the - # fragment in a instance variable similar to @content_for_layout. + # content_for("name") is a wrapper for capture which will + # make the fragment available by name to a yielding layout or template. # # layout.rhtml: # @@ -21,11 +20,11 @@ module ActionView # <head> # <title>layout with js</title> # <script type="text/javascript"> - # <%= @content_for_script %> + # <%= yield :script %> # </script> # </head> # <body> - # <%= @content_for_layout %> + # <%= yield %> # </body> # </html> # @@ -69,13 +68,9 @@ module ActionView end end - # Content_for will store the given block - # in an instance variable for later use in another template - # or in the layout. - # - # The name of the instance variable is content_for_<name> - # to stay consistent with @content_for_layout which is used - # by ActionView's layouts + # Calling content_for stores the block of markup for later use. + # Subsequently, you can make calls to it by name with <tt>yield</tt> + # in another template or in the layout. # # Example: # @@ -83,10 +78,17 @@ module ActionView # alert('hello world') # <% end %> # - # You can use @content_for_header anywhere in your templates. + # You can use yield :header anywhere in your templates. + # + # <%= yield :header %> # # NOTE: Beware that content_for is ignored in caches. So you shouldn't use it - # for elements that are going to be fragment cached. + # for elements that are going to be fragment cached. + # + # The deprecated way of accessing a content_for block was to use a instance variable + # named @content_for_#{name_of_the_content_block}. So <tt><% content_for('footer') %></tt> + # would be avaiable as <tt><%= @content_for_footer %></tt>. The preferred notation now is + # <tt><%= yield :footer %></tt>. def content_for(name, &block) eval "@content_for_#{name} = (@content_for_#{name} || '') + capture(&block)" end |