instance method
content_for?
Ruby on Rails 7.2.3
Since v3.0.20Signature
content_for?(name)
content_for? 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.
<%# 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) ? 'two-column' : 'one-column' %>"> <%= yield %> <%= yield :right_col %> </body> </html>
Parameters
-
namereq
Source
# File actionview/lib/action_view/helpers/capture_helper.rb, line 215
def content_for?(name)
@view_flow.get(name).present?
end
Defined in actionview/lib/action_view/helpers/capture_helper.rb line 215
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::CaptureHelper