Tilt template fragments
Asked Answered
C

1

5

Is it possible to render fragments of Tilt templates (i.e., without using a template file on disk)?

Background: I'd like to render inline template strings in a Ruby CGI program.

Chandless answered 21/5, 2012 at 14:0 Comment(0)
D
7

Yes. You can use any string data:

>> require 'haml'
>> template = Tilt::HamlTemplate.new { "%h1= 'Hello Haml!'" }
=> #<Tilt::HamlTemplate @file=nil ...>
>> template.render
=> "<h1>Hello Haml!</h1>"

See more examples in the docs

Dinh answered 21/5, 2012 at 14:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.