Module: Spina::Blocks::BlocksHelper

Defined in:
app/helpers/spina/blocks/blocks_helper.rb

Instance Method Summary collapse

Instance Method Details

#block_content(block, part_name = nil) ⇒ Object

Access a block’s content like page content Usage in block partial: block_content(block, :headline)



39
40
41
# File 'app/helpers/spina/blocks/blocks_helper.rb', line 39

def block_content(block, part_name = nil)
  block.content(part_name)
end

#block_has_content?(block, part_name) ⇒ Boolean

Check if a block has content for a given part

Returns:

  • (Boolean)


44
45
46
# File 'app/helpers/spina/blocks/blocks_helper.rb', line 44

def block_has_content?(block, part_name)
  block.has_content?(part_name)
end

#render_block(block) ⇒ Object

Render a single block using its block_template partial Usage: <%= render_block(some_block) %>



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/spina/blocks/blocks_helper.rb', line 22

def render_block(block)
  return unless block&.active?

  current_spina_theme = Spina::Current.theme || current_theme
  theme_name = current_spina_theme.name.parameterize.underscore

  partial_path = "#{theme_name}/blocks/#{block.block_template}"

  if lookup_context.exists?(partial_path, [], true)
    render partial: partial_path, locals: { block: block }
  else
    render_block_fallback(block)
  end
end

#render_blocks(page = nil) ⇒ Object

Render all blocks attached to the current page via PageBlocks Usage in a page template: <%= render_blocks %>



8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/spina/blocks/blocks_helper.rb', line 8

def render_blocks(page = nil)
  page ||= current_page
  return unless page.respond_to?(:page_blocks)

  page.page_blocks.sorted.includes(:block).each do |page_block|
    block = page_block.block
    next unless block&.active?

    concat render_block(block)
  end
end