Changeset 7148
- Timestamp:
- 06/28/07 18:32:34 (1 year ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/capture_helper.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r7138 r7148 1 1 *SVN* 2 3 * Improve capture helper documentation. #8796 [kampers] 2 4 3 5 * Prefix nested resource named routes with their action name, e.g. new_group_user_path(@group) instead of group_new_user_path(@group). The old nested action named route is deprecated in Rails 1.2.4. #8558 [David Chelimsky] trunk/actionpack/lib/action_view/helpers/capture_helper.rb
r7106 r7148 4 4 # can be used in other parts of a template or layout file. 5 5 # It provides a method to capture blocks into variables through capture and 6 # a way to capture a block of codefor use in a layout through content_for.6 # a way to capture a block of markup for use in a layout through content_for. 7 7 module CaptureHelper 8 # The capture method allows you to extract a part of thetemplate into a9 # variable. You can then use this va lue anywhere in your templates or layout.8 # The capture method allows you to extract part of a template into a 9 # variable. You can then use this variable anywhere in your templates or layout. 10 10 # 11 11 # ==== Examples … … 23 23 # end 24 24 # 25 # You can then use the content as a variable anywhere else. For 26 # example: 25 # You can then use that variable anywhere else. For example: 27 26 # 28 27 # <html> … … 47 46 end 48 47 49 # Calling content_for stores theblock of markup in an identifier for later use.50 # You can make subsequent calls to the stored content in another template or inthe layout51 # by calling it by name with<tt>yield</tt>.48 # Calling content_for stores a block of markup in an identifier for later use. 49 # You can make subsequent calls to the stored content in other templates or the layout 50 # by passing the identifier as an argument to <tt>yield</tt>. 52 51 # 53 52 # ==== Examples 54 53 # 55 # <% content_for ("authorized")do %>56 # alert('You are not authorized forthat!')54 # <% content_for :not_authorized do %> 55 # alert('You are not authorized to do that!') 57 56 # <% end %> 58 57 # 59 # You can then use <tt>yield : authorized</tt> anywhere in your templates.58 # You can then use <tt>yield :not_authorized</tt> anywhere in your templates. 60 59 # 61 # <%= yield : authorized if current_user == nil%>60 # <%= yield :not_authorized if current_user.nil? %> 62 61 # 63 # You can also use th ese variablesin a layout. For example:62 # You can also use this syntax alongside an existing call to <tt>yield</tt> in a layout. For example: 64 63 # 65 64 # <!-- This is the layout --> … … 74 73 # </html> 75 74 # 76 # And now we'll create a view that has a content_for call that75 # And now, we'll create a view that has a content_for call that 77 76 # creates the <tt>script</tt> identifier. 78 77 # … … 80 79 # Please login! 81 80 # 82 # <% content_for ("script")do %>83 # <script type="text/javascript">alert('You are not authorized for this action!')</script>81 # <% content_for :script do %> 82 # <script type="text/javascript">alert('You are not authorized to view this page!')</script> 84 83 # <% end %> 85 84 # 86 # Then in another view you may wantto do something like this:85 # Then, in another view, you could to do something like this: 87 86 # 88 87 # <%= link_to_remote 'Logout', :action => 'logout' %> 89 88 # 90 # <% content_for ("script")do %>89 # <% content_for :script do %> 91 90 # <%= javascript_include_tag :defaults %> 92 91 # <% end %> 93 92 # 94 # That will include Prototype and Scriptaculous into the page; this technique95 # is useful if you'll only be using these scripts on a few views.93 # That will place <script> tags for Prototype, Scriptaculous, and application.js (if it exists) 94 # on the page; this technique is useful if you'll only be using these scripts in a few views. 96 95 # 97 # NOTE: Beware that content_for is ignored in caches. So you shouldn't use it98 # for elements that are going to be fragment cached.96 # Also, note that content_for concatenates the blocks it is given for a particular 97 # identifier in order. For example: 99 98 # 100 # The deprecated way of accessing a content_for block was to use a instance variable 101 # named @@content_for_#{name_of_the_content_block}@. So <tt><%= content_for('footer') %></tt> 102 # would be avaiable as <tt><%= @content_for_footer %></tt>. The preferred notation now is 99 # <% content_for :navigation do %> 100 # <li><%= link_to 'Home', :action => 'index' %></li> 101 # <% end %> 102 # 103 # <!-- Add some other content, or use a different template: --> 104 # 105 # <% content_for :navigation do %> 106 # <li><%= link_to 'Login', :action => 'login' %></li> 107 # <% end %> 108 # 109 # Then, in another template or layout, this code would render both links in order: 110 # 111 # <ul><%= yield :navigation %></ul> 112 # 113 # WARNING: content_for is ignored in caches. So you shouldn't use it 114 # for elements that will be fragment cached. 115 # 116 # The deprecated way of accessing a content_for block is to use an instance variable 117 # named <tt>@content_for_#{name_of_the_content_block}</tt>. So <tt><%= content_for :footer %></tt> 118 # would be avaiable as <tt><%= @content_for_footer %></tt>. The preferred usage is now 103 119 # <tt><%= yield :footer %></tt>. 104 120 def content_for(name, content = nil, &block)