Class: Liquid::ContentFor

Inherits:
Block
  • Object
show all
Defined in:
app/liquid/blocks/content_for.rb

Overview

The content_for method allows you to insert content into a yield block in your layout. You only use content_for to insert content in named yields.

In your layout:

<title>{{ content_for title }}</title>

In the view:

{% content_for_title %} The title {% end_content_for_title %}

Will produce:

<title>The title</title>

Constant Summary collapse

SyntaxHelp =
"Syntax Error in tag 'content_for' - Valid syntax: content_for_[name]"

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ ContentFor

Returns a new instance of ContentFor.



20
21
22
23
24
25
26
27
28
# File 'app/liquid/blocks/content_for.rb', line 20

def initialize(tag_name, markup, tokens)
  if markup =~ /(#{VariableSignature}+)/
    @name = $1
  else
    raise SyntaxError.new(SyntaxHelp)
  end

  super
end

Instance Method Details

#block_delimiterObject



48
49
50
# File 'app/liquid/blocks/content_for.rb', line 48

def block_delimiter
  "end_#{block_name}"
end

#render(context) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/liquid/blocks/content_for.rb', line 30

def render(context)
  result = ''

  context.stack do
    result = render_all(@nodelist, context)
  end

  context.registers[:action_view].view_flow.content[@name] = '' unless context.registers[:action_view].view_flow.content.has_key? @name

  context.registers[:action_view].view_flow.content[@name].concat(result.html_safe)

  #context['content_for'][@name] = '' unless context['content_for'][@name]
  #context['content_for'][@name].concat(result.html_safe)

  ''

end