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*(.*)\s*/o
Instance Attribute Summary
Attributes inherited from Tag
#line, #nodelist, #options, #warnings
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens, options) ⇒ Assign
constructor
A new instance of Assign.
- #render(context) ⇒ Object
Methods inherited from Tag
#blank?, #name, new_with_options, #parse, #parse_with_selected_parser
Constructor Details
#initialize(tag_name, markup, tokens, options) ⇒ Assign
Returns a new instance of Assign.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/liquid/tags/assign.rb', line 15 def initialize(tag_name, markup, tokens, ) if markup =~ Syntax @to = $1 @from = Variable.new($2) else raise SyntaxError.new [:locale].t("errors.syntax.assign") end super end |
Instance Method Details
#render(context) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/liquid/tags/assign.rb', line 26 def render(context) val = @from.render(context) context.scopes.last[@to] = val context.resource_limits[:assign_score_current] += (val.respond_to?(:length) ? val.length : 1) '' end |