What is Liquid?

Liquid was originally created in 2006 by Tobias Lütke, the Founder and Creator of Shopify. The original purpose of Liquid was to create a safe way to expose data so that designers could independently build Shopify themes. Lots of companies today use Liquid in many different ways. If you keep an eye out, every once in awhile you’ll see some curly braces ({{ }}) and spot its syntax in the wild.

From a programmer's perspective, Liquid is incredibly useful. Businesses (including Shopify) want their software engineers to be focused on developing the next big feature to increase the capabilities of their products. They don't want their engineers building out custom themes for every new customer that is being onboarded. Software engineers are expensive and Shopify knows this.

Liquid solves that problem. With Liquid (and the right toolset), any person with the right knowledge can build out a theme that is customized for the customer. The only time the programmer needs to be involved is if there is an enhancement to the tools themselves that is needed or there is a bug that is preventing the theme from working correctly.

Liquid also solves a problem for programmers around security. Let's say that Shopify orders contain the user's credit card number (which they likely don't for PCI compliance rules). Programmers need to be sure that designers can't access this data since that is sensitive data that shouldn't be shared. Liquid gives programmers the ability to whitelist what data should be exposed through Liquid (and anything not whitelisted is kept a secret).

Liquid is a Programming Language

It says on the official Ruby Github page that Liquid is a "template engine". However, after digging into the code, I've realized that Liquid is a legitimate programming language. In fact, at a previous role we used to do “Dogfooding Challenges” where we would attempt to use our technology to solve programming challenges. Sometimes during these challenges, engineers would use Liquid to solve some pretty complex problems.

If you dig into how Liquid works, you will see that the raw Liquid code is tokenized and parsed, just as a compiled programming language would be. In fact, if you’re interested in learning about the inner-workings of Liquid itself, I recommend starting by learning about compilers. This is a pretty good writeup to start with.

Liquid supports variables, conditional statements, and looping in a similar way to any programming language.

Liquid Errors Gracefully

One of the most critical features of Liquid is how errors are handled. In a normal programming language, when something goes wrong the whole program may crash. Liquid was designed for designers and users, who may or may not know what they're doing. For Liquid, when something goes wrong, the error is caught and the result is that nothing is output.

As with all design decisions, this architecture has some pros and cons. The biggest advantage is that small mistakes don't crash the whole program. Instead, Liquid will continue on as if nothing ever happened, and hopefully your users don't notice. The biggest disadvantage is that it is not always obvious why your liquid isn't working. Other programming languages will often attempt to give you a clue about what is wrong using error messages.

Liquid is Portable

Liquid was originally built in the Ruby programming language and was packaged as a "Ruby Gem". However, since 2006, Liquid has been ported to many languages. Chances are, if you're working in a major programming language, there is a way for you to use Liquid in your application. At the time of writing, there are 16 ports listed on the official "Ports of Liquid to other environments" page.