aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/capture_helper.rb
diff options
context:
space:
mode:
authorDarragh Curran <darragh@peelmeagrape.net>2009-06-21 17:05:43 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-06-21 17:07:22 +0100
commit9cb8c812f2a23ab5653a7888740a014a02c97c18 (patch)
treeed207d0ec3e013b1921a1c8951ba46d51fa86967 /actionpack/lib/action_view/helpers/capture_helper.rb
parent66eb05821b1cb522f497c874e7708fe705fb8356 (diff)
downloadrails-9cb8c812f2a23ab5653a7888740a014a02c97c18.tar.gz
rails-9cb8c812f2a23ab5653a7888740a014a02c97c18.tar.bz2
rails-9cb8c812f2a23ab5653a7888740a014a02c97c18.zip
Add content_for?(:name) helper to check if content_for(:name) is present [#1311 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'actionpack/lib/action_view/helpers/capture_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/capture_helper.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb
index a8b5a9dbb9..c90acc5ac2 100644
--- a/actionpack/lib/action_view/helpers/capture_helper.rb
+++ b/actionpack/lib/action_view/helpers/capture_helper.rb
@@ -117,6 +117,28 @@ module ActionView
@_content_for[name]
end
+ # content_for? simply checks whether any content has been captured yet using content_for
+ # Useful to render parts of your layout differently based on what is in your views.
+ #
+ # ==== Examples
+ #
+ # Perhaps you will use different css in you layout if no content_for :right_column
+ #
+ # <%# This is the layout %>
+ # <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ # <head>
+ # <title>My Website</title>
+ # <%= yield :script %>
+ # </head>
+ # <body class="<%= content_for?(:right_col) ? 'one-column' : 'two-column' %>">
+ # <%= yield %>
+ # <%= yield :right_col %>
+ # </body>
+ # </html>
+ def content_for?(name)
+ @_content_for[name].present?
+ end
+
# Use an alternate output buffer for the duration of the block.
# Defaults to a new empty string.
def with_output_buffer(buf = nil) #:nodoc: