Liquid Engine for PHP

I’ve just finished working on my fork of the Liquid template engine.

Liquid is a templating library which was originally developed for usage with Ruby on Rails in Shopify. It uses a combination of tags, objects, and filters to load dynamic content. They are used inside Liquid template files, which are a group of files that make up a theme.

Here is a simple example:

<?php

use Liquid\Template;

$template = new Template();
$template->parse("Hello, {{ name }}!");
echo $template->render(array('name' => 'Alex');

// Will echo
// Hello, Alex!

The implementation my fork is based on was a little outdated and I decided that I could make some improvements to it.

Namespaces

Namespaces were added. Now all classes are under Liquid namespace. The library now implements PSR-4. The minimum required PHP version is 5.3 now.

Composer

You can now install the library via composer. Here is the package’s page.

composer create-project liquid/liquid

New standard filters

Implemented new standard filters: sort, sort_key, uniq, map, reverse, slice, round, ceil, floor, strip, lstrip, rstrip, replace, replace_first, remove, remove_first, prepend, append.

For the full list of supported filters read the Ruby implementation’s wiki page.

New tags

raw tag was added. The implementation of unless tag is in plans. You’re welcome to contribute.

Share this page on Twitter or Reddit