Sha256: d1773c932904dc097f60500ac044b8a959f0ecf7cff7bfea69927a5f3ba5fbda
Contents?: true
Size: 753 Bytes
Versions: 12
Compression:
Stored size: 753 Bytes
Contents
module Liquid # 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. # class Capture < Block Syntax = /(\w+)/ 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 def render(context) output = super context.scopes.last[@to] = output '' end end Template.register_tag('capture', Capture) end
Version data entries
12 entries across 12 versions & 3 rubygems