class Liquid::Context
- Liquid::Context
- Reference
- Object
Overview
A Context object provides the variables used by the Template object. These variables are stored
as key-value pairs of type String, Liquid::Any.
Defined in:
liquid/context.crliquid/json.cr
Constructors
-
.new(strict : Bool)
DEPRECATED Use
initialize(ErrorMode)instead. -
.new(error_mode : Liquid::Context::ErrorMode = :lax, data : Hash(String, Liquid::Any) = Hash(String, Any).new)
Creates a new
Contextwith the given error_mode and data.
Instance Method Summary
-
#[](var : String) : Any
Alias for
#get -
#[]=(var, value : Any) : Any
Alias for
#set -
#[]=(var, value : Any::Type) : Any
Alias for
#set -
#[]=(var : String, val : Array(String))
DEPRECATED Use
#setinstead. -
#[]=(var : String, val : Hash(String, String))
DEPRECATED Use
#setinstead. -
#[]?(var : String) : Any | Nil
Returns the value for the variable given by var, or nil if the variable isn't found.
- #error_mode : ErrorMode
- #error_mode=(error_mode : ErrorMode)
-
#errors : Array(Liquid::LiquidException)
Returns a list of errors found when rendering using this context.
- #get(var, strict : Bool)
-
#get(var : String) : Any
Fetch a variable from context, add
UndefinedVariableerror if the variable isn't found and behave according the error mode. - #lax?(*args, **options)
- #lax?(*args, **options, &)
-
#set(var : String, value : Any) : Any
Sets the value of var to the given value.
-
#set(var : String, value : Any::Type) : Any
Sets the value for var to an instance of
Liquid::Anygenerated from value. -
#set(var : String, json : JSON::Any) : Nil
Set the contents of a JSON::Any to the context.
-
#strict : Bool
DEPRECATED Use
#error_modeinstead. -
#strict=(value : Bool) : Bool
DEPRECATED Use
#error_mode=instead. - #strict?(*args, **options)
- #strict?(*args, **options, &)
-
#to_s(io : IO)
Appends a short String representation of this object which includes its class name and its object address.
- #warn?(*args, **options)
- #warn?(*args, **options, &)
Constructor Detail
Creates a new Context with the given error_mode and data.
Instance Method Detail
Returns the value for the variable given by var, or nil if the variable isn't found.
This doesn't trigger any exceptions or store any errors if the variable doesn't exists.
Returns a list of errors found when rendering using this context.
Fetch a variable from context, add UndefinedVariable error if the variable isn't found and behave according the
error mode.
Sets the value for var to an instance of Liquid::Any generated from value.
Set the contents of a JSON::Any to the context.
NOTE You need to require "liquid/json" to use this method.
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>