PHPackages                             liquid/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. liquid/liquid

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

liquid/liquid
=============

Liquid template engine for PHP

1.4.44(11mo ago)1854.8M—3.8%64[17 issues](https://github.com/kalimatas/php-liquid/issues)[6 PRs](https://github.com/kalimatas/php-liquid/pulls)20MITPHPPHP ^7.4 || ^8.0CI passing

Since Sep 7Pushed 5mo ago8 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (55)Used By (20)

Liquid template engine for PHP [![CI](https://github.com/kalimatas/php-liquid/actions/workflows/tests.yaml/badge.svg)](https://github.com/kalimatas/php-liquid/actions/workflows/tests.yaml) [![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 8.2+

Some earlier versions could be used with PHP 5.x/7.x, 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

64

—

FairBetter than 99% of packages

Maintenance60

Regular maintenance activity

Popularity62

Solid adoption and visibility

Community40

Growing community involvement

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 73.7% 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 ~76 days

Recently: every ~130 days

Total

52

Last Release

353d ago

PHP version history (7 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.19PHP ^7.3

1.4.20PHP ^7.3 || ^8.0

1.4.38PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/faadb012b9794e11ded2bfa09003221ae2788cb78866752c833c2bd2a705114b?d=identicon)[kalimatas](/maintainers/kalimatas)

---

Top Contributors

[![sanmai](https://avatars.githubusercontent.com/u/139488?v=4)](https://github.com/sanmai "sanmai (294 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 (16 commits)")[![PNixx](https://avatars.githubusercontent.com/u/1117351?v=4)](https://github.com/PNixx "PNixx (9 commits)")[![live627](https://avatars.githubusercontent.com/u/431799?v=4)](https://github.com/live627 "live627 (7 commits)")[![warezthebeef](https://avatars.githubusercontent.com/u/521746?v=4)](https://github.com/warezthebeef "warezthebeef (6 commits)")[![NathanBaulch](https://avatars.githubusercontent.com/u/249604?v=4)](https://github.com/NathanBaulch "NathanBaulch (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)")[![schmitty42](https://avatars.githubusercontent.com/u/8099304?v=4)](https://github.com/schmitty42 "schmitty42 (2 commits)")[![jadb](https://avatars.githubusercontent.com/u/33527?v=4)](https://github.com/jadb "jadb (2 commits)")[![jkrenge](https://avatars.githubusercontent.com/u/625618?v=4)](https://github.com/jkrenge "jkrenge (1 commits)")[![QuentinBellus](https://avatars.githubusercontent.com/u/7331499?v=4)](https://github.com/QuentinBellus "QuentinBellus (1 commits)")[![fedeisas](https://avatars.githubusercontent.com/u/251675?v=4)](https://github.com/fedeisas "fedeisas (1 commits)")[![schmoove](https://avatars.githubusercontent.com/u/1321541?v=4)](https://github.com/schmoove "schmoove (1 commits)")[![shawngoh87](https://avatars.githubusercontent.com/u/23649231?v=4)](https://github.com/shawngoh87 "shawngoh87 (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)")

---

Tags

templateliquid

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/liquid-liquid/health.svg)](https://phpackages.com/packages/liquid-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)[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)
