There are few significant changes that you need to care about when using liquid instead of ERB or HAML.
- None of the local members or class members declared will be available in your template
- The locals hash is respected even for the layout.
- You have to use {{ content }} in your layouts, instead of yielding.
And finally a "hello world" sinatra app with liquid.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.unshift File.join(File.dirname(__FILE__),'lib/sinatra/lib') | |
require 'rubygems' | |
require 'sinatra' | |
use_in_file_templates! | |
get '/:name' do | |
params['title'] = 'Sinatra and Liquid rocks' | |
liquid :index, :locals => params | |
end | |
__END__ | |
@@layout | |
<html> | |
<head><title>{{title}}<title></head> | |
<body> | |
{{content}} | |
</body> | |
</html> | |
@@ index | |
<h1>{{ name }}</h1> |
Do let me know if you like it.
No comments:
Post a Comment