Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tilt template fragments

Tags:

ruby

tilt

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.

like image 523
Sunder Avatar asked May 21 '12 14:05

Sunder


1 Answers

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

like image 94
Casper Avatar answered Dec 09 '22 07:12

Casper