PHPackages                             thomasgreen/liquid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. thomasgreen/liquid

ActiveLibrary[Templating &amp; Views](/categories/templating)

thomasgreen/liquid
==================

Liquid template engine for PHP

1.4.20(6y ago)08MITPHPPHP ^5.5.9

Since Sep 7Pushed 6y agoCompare

[ Source](https://github.com/thomasgreen/php-liquid)[ Packagist](https://packagist.org/packages/thomasgreen/liquid)[ Docs](https://github.com/thomasgreen/php-liquid)[ RSS](/packages/thomasgreen-liquid/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (4)Versions (30)Used By (0)

Liquid template engine for PHP [![Build Status](https://camo.githubusercontent.com/77627f1c015fef66c27e77d5ade3a950a20879e096192bd85b338160c365a51c/68747470733a2f2f7472617669732d63692e6f72672f6b616c696d617461732f7068702d6c69717569642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kalimatas/php-liquid) [![Coverage Status](https://camo.githubusercontent.com/a9ff94064ab5197f0b7690647965a449e1924c58699b61d1e6276318b7fb004c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6b616c696d617461732f7068702d6c69717569642f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/kalimatas/php-liquid?branch=master) [![Total Downloads](https://camo.githubusercontent.com/b0d4f3703e5d137139614ad6cb916f64bd178c1b6a7d2c6f38a74a0203255753/68747470733a2f2f706f7365722e707567782e6f72672f6c69717569642f6c69717569642f646f776e6c6f6164732e737667)](https://packagist.org/packages/liquid/liquid)
==============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#liquid-template-engine-for-php---)

Liquid is a PHP port of the [Liquid template engine for Ruby](https://github.com/Shopify/liquid), which was written by Tobias Lutke. Although there are many other templating engines for PHP, including Smarty (from which Liquid was partially inspired), Liquid had some advantages that made porting worthwhile:

- Readable and human friendly syntax, that is usable in any type of document, not just html, without need for escaping.
- Quick and easy to use and maintain.
- 100% secure, no possibility of embedding PHP code.
- Clean OO design, rather than the mix of OO and procedural found in other templating engines.
- Seperate compiling and rendering stages for improved performance.
- Easy to extend with your own "tags and filters":.
- 100% Markup compatibility with a Ruby templating engine, making templates usable for either.
- Unit tested: Liquid is fully unit-tested. The library is stable and ready to be used in large projects.

Why Liquid?
-----------

[](#why-liquid)

Why another templating library?

Liquid was written to meet three templating library requirements: good performance, easy to extend, and simply to use.

Installing
----------

[](#installing)

You can install this lib via [composer](https://getcomposer.org/):

```
composer require liquid/liquid

```

Example template
----------------

[](#example-template)

```
{% if products %}

	{% for product in products %}

		{{ product.name }}
		Only {{ product.price | price }}

		{{ product.description | prettyprint | paragraph }}

		{{ 'it rocks!' | paragraph }}

	{% endfor %}

{% endif %}

```

How to use Liquid
-----------------

[](#how-to-use-liquid)

The main class is `Liquid::Template` class. There are two separate stages of working with Liquid templates: parsing and rendering. Here is a simple example:

```
use Liquid\Template;

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

// Will echo
// Hello, Alex!

```

To find more examples have a look at the `examples` directory or at the original Ruby implementation repository's [wiki page](https://github.com/Shopify/liquid/wiki).

Advanced usage
--------------

[](#advanced-usage)

You would probably want to add a caching layer (at very least a request-wide one), enable context-aware automatic escaping, and do load includes from disk with full file names.

```
use Liquid\Liquid;
use Liquid\Template;
use Liquid\Cache\Local;

Liquid::set('INCLUDE_SUFFIX', '');
Liquid::set('INCLUDE_PREFIX', '');
Liquid::set('INCLUDE_ALLOW_EXT', true);
Liquid::set('ESCAPE_BY_DEFAULT', true);

$template = new Template(__DIR__.'/protected/templates/');

$template->parse("Hello, {% include 'honorific.html' %}{{ plain-html | raw }} {{ comment-with-xss }}");
$template->setCache(new Local());

echo $template->render([
    'name' => 'Alex',
    'plain-html' => 'Your comment was:',
    'comment-with-xss' => 'alert();',
]);

```

Will output:

```
Hello, Mx. Alex
Your comment was: &lt;script&gt;alert();&lt;/script&gt;

```

Note that automatic escaping is not a standard Liquid feature: use with care.

Similarly, the following snippet will parse and render `templates/home.liquid` while storing parsing results in a class-local cache:

```
\Liquid\Liquid::set('INCLUDE_PREFIX', '');

$template = new \Liquid\Template(__DIR__ . '/protected/templates');
$template->setCache(new \Liquid\Cache\Local());
echo $template->parseFile('home')->render();

```

If you render the same template over and over for at least a dozen of times, the class-local cache will give you a slight speed up in range of some milliseconds per render depending on a complexity of your template.

You should probably extend `Liquid\Template` to initialize everything you do with `Liquid::set` in one place.

### Custom filters

[](#custom-filters)

Adding filters has never been easier.

```
$template = new Template();
$template->registerFilter('absolute_url', function ($arg) {
    return "https://www.example.com$arg";
});
$template->parse("{{ my_url | absolute_url }}");
echo $template->render(array(
    'my_url' => '/test'
));
// expect: https://www.example.com/test

```

Requirements
------------

[](#requirements)

- PHP 7.0+

Some earlier versions could be used with PHP 5.3/5.4/5.5/5.6, though they're not supported anymore.

Issues
------

[](#issues)

Have a bug? Please create an issue here on GitHub!

Fork notes
----------

[](#fork-notes)

This fork is based on [php-liquid](https://github.com/harrydeluxe/php-liquid) by Harald Hanek.

It contains several improvements:

- namespaces
- installing via composer
- new standard filters
- `raw` tag added

Any help is appreciated!

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 76.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~75 days

Recently: every ~61 days

Total

28

Last Release

2238d ago

PHP version history (5 changes)1.0PHP &gt;= 5.3

1.4.0PHP &gt;= 5.6

1.4.9PHP &gt;= 7

1.4.14PHP &gt;=7.0

1.4.18PHP ^5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/6081af833b86d1b6585afdf341f566335d81294a1e1fd6c0e5a795066a14e656?d=identicon)[tomgreen32](/maintainers/tomgreen32)

---

Top Contributors

[![sanmai](https://avatars.githubusercontent.com/u/139488?v=4)](https://github.com/sanmai "sanmai (257 commits)")[![ryanmac](https://avatars.githubusercontent.com/u/43529?v=4)](https://github.com/ryanmac "ryanmac (34 commits)")[![funkjedi](https://avatars.githubusercontent.com/u/9314?v=4)](https://github.com/funkjedi "funkjedi (14 commits)")[![NathanBaulch](https://avatars.githubusercontent.com/u/249604?v=4)](https://github.com/NathanBaulch "NathanBaulch (6 commits)")[![warezthebeef](https://avatars.githubusercontent.com/u/521746?v=4)](https://github.com/warezthebeef "warezthebeef (6 commits)")[![jfoucher](https://avatars.githubusercontent.com/u/152015?v=4)](https://github.com/jfoucher "jfoucher (4 commits)")[![PATROMO](https://avatars.githubusercontent.com/u/318564?v=4)](https://github.com/PATROMO "PATROMO (3 commits)")[![edwardoka](https://avatars.githubusercontent.com/u/1197105?v=4)](https://github.com/edwardoka "edwardoka (3 commits)")[![v1o](https://avatars.githubusercontent.com/u/1176288?v=4)](https://github.com/v1o "v1o (3 commits)")[![jadb](https://avatars.githubusercontent.com/u/33527?v=4)](https://github.com/jadb "jadb (2 commits)")[![daniel-zahariev](https://avatars.githubusercontent.com/u/263063?v=4)](https://github.com/daniel-zahariev "daniel-zahariev (1 commits)")[![timglabisch](https://avatars.githubusercontent.com/u/689269?v=4)](https://github.com/timglabisch "timglabisch (1 commits)")[![developedbyme](https://avatars.githubusercontent.com/u/261461?v=4)](https://github.com/developedbyme "developedbyme (1 commits)")[![QuentinBellus](https://avatars.githubusercontent.com/u/7331499?v=4)](https://github.com/QuentinBellus "QuentinBellus (1 commits)")

---

Tags

templateliquid

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/thomasgreen-liquid/health.svg)

```
[![Health](https://phpackages.com/badges/thomasgreen-liquid/health.svg)](https://phpackages.com/packages/thomasgreen-liquid)
```

###  Alternatives

[phpoffice/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

7.6k34.7M186](/packages/phpoffice-phpword)[rize/uri-template

PHP URI Template (RFC 6570) supports both expansion &amp; extraction

420137.3M46](/packages/rize-uri-template)[liquid/liquid

Liquid template engine for PHP

1854.8M25](/packages/liquid-liquid)[simexis/laravel-liquid

Liquid template engine for Laravel

181.5k](/packages/simexis-laravel-liquid)[larablocks/pigeon

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

143.7k](/packages/larablocks-pigeon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
