class

Liquid::Context

Inherits Reference / Object

A Context object provides the variables used by the Template object. These variables are stored as key-value pairs of type String, Liquid::Any.

Constructors

new(strict : Bool)

DEPRECATED Use initialize(ErrorMode) instead.

Source
new(error_mode : Liquid::Context::ErrorMode = :lax, data : Hash(String, Liquid::Any) = Hash(String, Any).new)

Creates a new Context with the given error_mode and data.

Source

Instance methods

[](var : String) : Any

Alias for #get

Source
[]=(var, value : Any) : Any

Alias for #set

Source
[]=(var, value : Any::Type) : Any

Alias for #set

Source
[]=(var : String, val : Array(String))

DEPRECATED Use #set instead.

Source
[]=(var : String, val : Hash(String, String))

DEPRECATED Use #set instead.

Source
[]?(var : String) : Any | Nil

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.

Source
error_mode
Source
error_mode=(error_mode : ErrorMode)
Source
errors

Returns a list of errors found when rendering using this context.

Source
get(var, strict : Bool)

DEPRECATED Use #[] or #[]? instead.

Source
get(var : String) : Any

Fetch a variable from context, add UndefinedVariable error if the variable isn't found and behave according the error mode.

Source
lax?(*args, **options)
Source
lax?(*args, **options, &)
Source
set(var : String, value : Any) : Any

Sets the value of var to the given value.

Source
set(var : String, value : Any::Type) : Any

Sets the value for var to an instance of Liquid::Any generated from value.

Source
set(var : String, json : JSON::Any) : Nil

Set the contents of a JSON::Any to the context.

NOTE: You need to require "liquid/json" to use this method.

Source
strict

DEPRECATED Use #error_mode instead.

Source
strict=(value : Bool) : Bool

DEPRECATED Use #error_mode= instead.

Source
strict?(*args, **options)
Source
strict?(*args, **options, &)
Source
to_s(io : IO)

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>
Source
warn?(*args, **options)
Source
warn?(*args, **options, &)
Source

Nested types