class Liquid::Capture

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.

Constants

Syntax

Public Class Methods

new(tag_name, markup, options) click to toggle source
Calls superclass method Liquid::Block::new
# File lib/liquid/tags/capture.rb, line 18
def initialize(tag_name, markup, options)
  super
  if markup =~ Syntax
    @to = Regexp.last_match(1)
  else
    raise SyntaxError, options[:locale].t("errors.syntax.capture")
  end
end

Public Instance Methods

blank?() click to toggle source
# File lib/liquid/tags/capture.rb, line 35
def blank?
  true
end
render_to_output_buffer(context, output) click to toggle source
# File lib/liquid/tags/capture.rb, line 27
def render_to_output_buffer(context, output)
  context.resource_limits.with_capture do
    capture_output = render(context)
    context.scopes.last[@to] = capture_output
  end
  output
end