Class: Locomotive::Liquid::Tags::SessionAssign
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Locomotive::Liquid::Tags::SessionAssign
- Defined in:
- lib/locomotive/liquid/tags/session_assign.rb
Overview
Assign sets a variable in your session.
{% session_assign foo = 'monkey' %}
You can then use the variable later in the page.
{{ session.foo }}
Constant Summary collapse
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens, context) ⇒ SessionAssign
constructor
A new instance of SessionAssign.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens, context) ⇒ SessionAssign
Returns a new instance of SessionAssign.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/locomotive/liquid/tags/session_assign.rb', line 16 def initialize(tag_name, markup, tokens, context) if markup =~ Syntax @to = $1 @from = $2 else raise ::Liquid::SyntaxError.new("Syntax Error in 'session_assign' - Valid syntax: assign [var] = [source]") end super end |
Instance Method Details
#render(context) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/locomotive/liquid/tags/session_assign.rb', line 27 def render(context) controller = context.registers[:controller] controller.session[@to.to_sym] = context[@from] '' end |