harrydeluxe / php-liquid

A PHP port of Ruby's Liquid Templates
http://www.delacap.com/artikel/Liquid-Templates/
MIT License
239 stars 119 forks source link

Liquid template engine for PHP Build Status

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 Liquid?

Why another templating library?

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

Installing

You can install this lib via composer:

composer create-project liquid/liquid

Example template

{% 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 %}

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' => '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.

Requirements

Issues

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

https://github.com/harrydeluxe/php-liquid/issues

Fork notes and contributors

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:

Any help is appreciated!