Liquid (liquid)¶ ↑
Liquid is designed to be a safe template system and therefore does not provide direct access to execuatable scopes. In order to support a scope, the scope must be able to represent itself as a hash by responding to to_h. If the scope does not respond to to_h it will be ignored.
LiquidTemplate does not support yield blocks.
Example¶ ↑
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<h1>Hello {{ world }}!</h1>
</body>
</html>
Usage¶ ↑
Tilt::LiquidTemplate is registered for all files ending in .liquid by default. Liquid templates support locals and objects that respond to to_h as scopes:
>> require 'liquid'
>> require 'tilt'
>> template = Tilt.new('hello.liquid')
=> #<Tilt::LiquidTemplate @file='hello.liquid'>
>> scope = { :title => "Hello Liquid Templates" }
>> template.render(nil, :world => "Liquid")
=> "
<html>
<head>
<title>Hello Liquid Templates</title>
</head>
<body>
<h1>Hello Liquid!</h1>
</body>
</html>"
Or, use Tilt::LiquidTemplate directly to process strings:
>> require 'liquid'
>> template = Tilt::LiquidTemplate.new { "<h1>Hello Liquid!</h1>" }
=> #<Tilt::LiquidTemplate @file=nil ...>
>> template.render
=> "<h1>Hello Liquid!</h1>"
NOTE: It’s suggested that your program require 'liquid' at load time when using this template engine within a threaded environment.
See also¶ ↑
Related module¶ ↑
Required files
- liquid