Class: Liquid::Capture
Overview
Capture stores the result of a block into a variable without rendering it inplace.
{% capture heading %}
Monkeys!
{% endcapture %}
...
<h1>{{ heading }}</h1>
Capture is useful for saving content for use later in your template, such as in a sidebar or footer.
Constant Summary
- Syntax =
/(\w+)/
Constants inherited from Block
Block::ContentOfVariable, Block::FullToken, Block::IsTag, Block::IsVariable
Instance Attribute Summary
Attributes inherited from Tag
Instance Method Summary (collapse)
-
- (Capture) initialize(tag_name, markup, tokens)
constructor
A new instance of Capture.
- - (Object) render(context)
Methods inherited from Block
#block_delimiter, #block_name, #create_variable, #end_tag, #parse, #unknown_tag
Methods inherited from Tag
Constructor Details
- (Capture) initialize(tag_name, markup, tokens)
A new instance of Capture
17 18 19 20 21 22 23 24 25 |
# File 'lib/liquid/tags/capture.rb', line 17 def initialize(tag_name, markup, tokens) if markup =~ Syntax @to = $1 else raise SyntaxError.new("Syntax Error in 'capture' - Valid syntax: capture [var]") end super end |
Instance Method Details
- (Object) render(context)
27 28 29 30 31 |
# File 'lib/liquid/tags/capture.rb', line 27 def render(context) output = super context.scopes.last[@to] = output '' end |