Liquid: Six Lessons Learned

Liquid: Six Lessons Learned

Liquid is an open-source template language originally created by Shopify to create templates compatible with the ever-changing content in customer storefronts. It successfully sandboxes user logic to prevent exposing security vulnerabilities to end users.

WebVolta has used Liquid in conjunction with LocomotiveCMS, an open-source CMS that also utilizes the Liquid template language. Here are six of the lessons we’ve learned over the years:

1. Liquid can be used to render templates in text-based format.

We’ve used Liquid to render HTML, XML and SVG graphics. The language is quite flexible and effective inside various formats.

2. Liquid can be used to render anything into a template.

CSS changes and HTML template modifications are two capabilities beyond simply rendering text into a document that we’ve found particularly useful.

3. Liquid uses a lot of memory.

Templates with complex structure and encoded binary data will use up a lot of memory. Be warned.

4. The two Liquid invocations can be a bit confusing.

The double curly brace {{ something }} and {% something else %} can get a bit confusing. According to the Liquid documentation, the double curly brace is for rendering “objects” (e.g., JSON objects or a hash of data), and the curly brace percent is used for “flow control” within the document. Custom Liquid tags should also be rendered with {% tag %}.

5. The Liquid rendering stack is multi-purpose.

Liquid tags contain a shared context that can be accessed from within the tags. This can be used to stash information to return to after the rendering. The current_context tag gives you access to the current context object. We use current_context to grab the first environment and store a state that needs to be accessed outside of the renderer. (We’ll have a full-length post fleshing out this process soon!)

6. Liquid isn’t limited to Ruby.

Multiple Liquid ports exist, including Javascript and Elixir.

Liquid is a versatile template language, with endless possibilities for solving problems. Whether you’re concerned with end-user or internal template, Liquid gives you the flexibility you need while keeping your data and applications safe.

If you’re looking for custom-built templates or if you’re interested in learning more about Liquid’s capabilities, use our Contact Us page to drop us a quick note. We’d love to hear from you!

pin-icon phone