Skip to content

Commit ab158c7

Browse files
committed
Better documentation on how the 'container_has_block?' tag works
1 parent 0b29f2b commit ab158c7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

app/helpers/cms/page_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ def container(name)
2121
end
2222
end
2323

24+
# Determine if a given container has any blocks within it. Useful for determine if markup should be conditionally included
25+
# when a block is present, but not shown if no block was added. For example:
26+
#
27+
# <% unless container_has_block? :sidebar %>
28+
# <div id="sidebar">
29+
# <%= container :sidebar %>
30+
# </div>
31+
# <% end %>
32+
#
33+
# @param [Symbol] name The name of the container to check
34+
# @param [Proc] block
35+
# @return [Boolean] True if the container has one or more blocks, or if we are in edit mode. False otherwise.
2436
def container_has_block?(name, &block)
2537
has_block = (@mode == "edit") || current_page.connectable_count_for_container(name) > 0
2638
logger.info "mode = #{@mode}, has_block = #{has_block}"

0 commit comments

Comments
 (0)