Class: Liquid::Assign
Overview
Assign sets a variable in your template.
{% assign foo = 'monkey' %}
You can then use the variable later in the page.
{{ foo }}
Constant Summary collapse
- Syntax =
/(#{VariableSignature}+)\s*=\s*(#{QuotedFragment}+)/
Instance Attribute Summary
Attributes inherited from Tag
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ Assign
constructor
A new instance of Assign.
- #render(context) ⇒ Object
Methods inherited from Tag
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ Assign
Returns a new instance of Assign.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/liquid/tags/assign.rb', line 14 def initialize(tag_name, markup, tokens) if markup =~ Syntax @to = $1 @from = $2 else raise SyntaxError.new("Syntax Error in 'assign' - Valid syntax: assign [var] = [source]") end super end |
Instance Method Details
#render(context) ⇒ Object
25 26 27 28 |
# File 'lib/liquid/tags/assign.rb', line 25 def render(context) context.scopes.last[@to] = context[@from] '' end |