mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
4087a94d881c53b803f1d682db7e4676a6f4d714
Thanks to phaer: https://gist.github.com/1020852 YO DAWG, WE HEARD YOU LIKE LIQUID SO WE PUT A RAW TAG IN YOUR LIQUID SO YOU CAN HAVE LIQUID IN YOUR LIQUID
Liquid template engine
Introduction
Liquid is a template engine which I wrote for very specific requirements
- It has to have beautiful and simple markup. Template engines which don't produce good looking markup are no fun to use.
- It needs to be non evaling and secure. Liquid templates are made so that users can edit them. You don't want to run code on your server which your users wrote.
- It has to be stateless. Compile and render steps have to be seperate so that the expensive parsing and compiling can be done once and later on you can just render it passing in a hash with local variables and objects.
Why should I use Liquid
- You want to allow your users to edit the appearance of your application but don't want them to run insecure code on your server.
- You want to render templates directly from the database
- You like smarty (PHP) style template engines
- You need a template engine which does HTML just as well as emails
- You don't like the markup of your current templating engine
What does it look like?
{% for product in products %}
-
{{product.name}}
Only {{product.price | price }}
{{product.description | prettyprint | paragraph }}
</li>
{% endfor %}
Howto use Liquid
Liquid supports a very simple API based around the Liquid::Template class. For standard use you can just pass it the content of a file and call render with a parameters hash.
@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
@template.render( 'name' => 'tobi' ) # => "hi tobi"
Languages
Ruby
84.7%
Liquid
15.3%