class Liquid::Template

Overview

Templates are central to liquid. Interpretating templates is a two step process. First you compile the source code you got. During compile time some extensive error checking is performed. Your code should expect to get some SyntaxErrors.

After you have a compiled template you can then render it. You can use a compiled template over and over again and keep it cached.

Example:

template = Liquid::Template.parse(source) template.render("user_name" => "bob")

Defined in:

liquid/template.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new #

creates a new Template from an array of tokens. Use Template.parse instead


[View source]

Class Method Detail

def self.file_system #

[View source]
def self.file_system=(obj : Liquid::FileSystem) #

[View source]
def self.parse(source) #

creates a new Template object from liquid source code


[View source]
def self.register_filter(filter : Filter.class) #

Pass a module with filter methods which should be available to all liquid views. Good for registering the standard library


[View source]
def self.register_tag(name, klass) #

[View source]
def self.tags #

[View source]

Instance Method Detail

def assigns #

[View source]
def errors #

[View source]
def instance_assigns #

[View source]
def parse(source) #

Parse source code. Returns self for easy chaining


[View source]
def registers #

[View source]
def render(context : Context, registers : Hash(Symbol, Type), filters : Array(Filter.class)) #

[View source]
def render(environment, registers : Hash(Symbol, Type), filters : Array(Filter.class)) #

[View source]
def render(context : Context, registers : Hash(Symbol, Type)) #

[View source]
def render(context : Context, filters : Array(Filter.class)) #

[View source]
def render(environment, registers : Hash(Symbol, Type)) #

[View source]
def render(environment, filters : Array(Filter.class)) #

[View source]
def render(context : Context) #

Render takes a hash with local variables.

if you use the same filters over and over again consider registering them globally with Template.register_filter

Following options can be passed:

  • filters : array with local filters
  • registers : hash with register variables. Those can be accessed from filters and tags and might be useful to integrate liquid more with its host application

[View source]
def render(environment) #

[View source]
def render #

[View source]
def render!(*args) #

[View source]
def root : Liquid::Document? #

[View source]
def root=(root : Nil | Liquid::Document) #

[View source]