--- !ruby/object:RI::MethodDescription 
aliases: []

block_params: 
comment: 
- !ruby/struct:SM::Flow::P 
  body: Calling content_for stores a block of markup in an identifier for later use. You can make subsequent calls to the stored content in other templates or the layout by passing the identifier as an argument to <tt>yield</tt>.
- !ruby/struct:SM::Flow::H 
  level: 4
  text: Examples
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;% content_for :not_authorized do %&gt;\n    alert('You are not authorized to do that!')\n  &lt;% end %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: You can then use <tt>yield :not_authorized</tt> anywhere in your templates.
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;%= yield :not_authorized if current_user.nil? %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "You can also use this syntax alongside an existing call to <tt>yield</tt> in a layout. For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;%# This is the layout %&gt;\n  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;\n  &lt;head&gt;\n    &lt;title&gt;My Website&lt;/title&gt;\n    &lt;%= yield :script %&gt;\n  &lt;/head&gt;\n  &lt;body&gt;\n    &lt;%= yield %&gt;\n  &lt;/body&gt;\n  &lt;/html&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: And now, we'll create a view that has a content_for call that creates the <tt>script</tt> identifier.
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;%# This is our view %&gt;\n  Please login!\n\n  &lt;% content_for :script do %&gt;\n    &lt;script type=&quot;text/javascript&quot;&gt;alert('You are not authorized to view this page!')&lt;/script&gt;\n  &lt;% end %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "Then, in another view, you could to do something like this:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;%= link_to_remote 'Logout', :action =&gt; 'logout' %&gt;\n\n  &lt;% content_for :script do %&gt;\n    &lt;%= javascript_include_tag :defaults %&gt;\n  &lt;% end %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: That will place &lt;script&gt; tags for Prototype, Scriptaculous, and application.js (if it exists) on the page; this technique is useful if you'll only be using these scripts in a few views.
- !ruby/struct:SM::Flow::P 
  body: "Note that content_for concatenates the blocks it is given for a particular identifier in order. For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;% content_for :navigation do %&gt;\n    &lt;li&gt;&lt;%= link_to 'Home', :action =&gt; 'index' %&gt;&lt;/li&gt;\n  &lt;% end %&gt;\n\n  &lt;%#  Add some other content, or use a different template: %&gt;\n\n  &lt;% content_for :navigation do %&gt;\n    &lt;li&gt;&lt;%= link_to 'Login', :action =&gt; 'login' %&gt;&lt;/li&gt;\n  &lt;% end %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "Then, in another template or layout, this code would render both links in order:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;ul&gt;&lt;%= yield :navigation %&gt;&lt;/ul&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "Lastly, simple content can be passed as a parameter:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;% content_for :script, javascript_include_tag(:defaults) %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "WARNING: content_for is ignored in caches. So you shouldn't use it for elements that will be fragment cached."
- !ruby/struct:SM::Flow::P 
  body: The deprecated way of accessing a content_for block is to use an instance variable named <tt>@content_for_#{name_of_the_content_block}</tt>. The preferred usage is now <tt>&lt;%= yield :footer %&gt;</tt>.
full_name: ActionView::Helpers::CaptureHelper#content_for
is_singleton: false
name: content_for
params: (name, content = nil, &block)
visibility: public
