Liquid is a PHP port of the Liquid template engine for Ruby, 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:
Why another templating library?
Liquid was written to meet three templating library requirements: good performance, easy to extend, and simply to use.
You can install this lib via composer:
composer create-project liquid/liquid
{% if products %}
<ul id="products">
{% for product in products %}
<li>
<h2>{{ product.name }}</h2>
Only {{ product.price | price }}
{{ product.description | prettyprint | paragraph }}
{{ 'it rocks!' | paragraph }}
</li>
{% endfor %}
</ul>
{% endif %}
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' => 'World');
// Will echo
// Hello, World!
To find more examples have a look at the examples
directory or at the original Ruby implementation repository's wiki page.
Have a bug? Please create an issue here on GitHub!
https://github.com/harrydeluxe/php-liquid/issues
This fork is based on php-liquid by Mateo Murphy. kalimatas has contributed a lot in his fork to bring Liquid to the new state. Thank you so much!
It contains several improvements:
raw
tag addedAny help is appreciated!