Method: Sinatra::ContentFor#content_for?

Defined in:
lib/sinatra/content_for.rb

#content_for?(key) ⇒ Boolean

Check if a block of content with the given key was defined. For example:

<% content_for :head do %>
  <script type="text/javascript" src="/foo.js"></script>
<% end %>

<% if content_for? :head %>
  <span>content "head" was defined.</span>
<% end %>

Returns:

  • (Boolean)


148
149
150
# File 'lib/sinatra/content_for.rb', line 148

def content_for?(key)
  content_blocks[key.to_sym].any?
end