Introducing Liquid

Posted by tobi — 11:03 AM Nov 05

I finally spent some time finishing up Liquid to get the 1.0 version of it out the door. I have been talking about Liquid here and there, but lets start at the beginning.

Liquid is a simple text processor. You give it text, instrumented with certain tags and a hash with variables, and it will merge them together and return the output in similar fashion to ERB. The difference is that Liquid does not use eval to work. This means that you can store liquid based templates in your database and let your users edit the appearance of your pages without risking the security of your server’s data.

What does that look like?

When starting to look around for inspiration for liquid’s syntax I found django templates from the python community. It is itself based on smarty, but features a very clean syntax:

    {% for product in products %}
  • {{product.name}}

    Only {{product.price | price }} {{product.description | prettyprint | paragraph }}
  • {% endfor %}

How can I try it out?

If you are running the latest and greatest rails you should have noticed the new script/plugin script. Liquid comes packaged as a plugin. After dropping it in your vendor/plugins folder you can start using it right away by renaming your views to *.liquid.

Where did that come from?!

Liquid is another extraction from Shopify next to Money, Paypal and the soon to be released ActiveMerchant. The nice thing is its something users can more directly profit from then say the Paypal bindings ( which either work or not ). So if you are planning to use shopify, have a look at liquid—all the improvements to it will benefit you directly as soon as Shopify is released.

Read more on the Liquid home page.

Comments