Download the PHP package keepsuit/liquid without Composer
On this page you can find all versions of the php package keepsuit/liquid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download keepsuit/liquid
More information about keepsuit/liquid
Files in keepsuit/liquid
Package liquid
Short Description PHP implementation of liquid markup language
License MIT
Homepage https://github.com/keepsuit/php-liquid
Informations about the package liquid
PHP implementation of Liquid markup language
This is a PHP porting of the Shopify Liquid template engine.
If you are using laravel, you can use the laravel-liquid package.
Liquid is a template engine with interesting advantages:
- It is easy to learn and has a simple syntax.
- It is safe since it does not allow users to run insecure code on your server.
- It is extensible, allowing you to add your own filters and tags.
Shopify Liquid version compatibility
PHP Liquid | Shopify Liquid |
---|---|
v0.8 | v5.7 |
v0.7 | v5.6 |
v0.1 - v0.6 | v5.5 |
Differences from Shopify Liquid
- Error Modes are not implemented, the parsing is always strict.
include
tag is not implemented because it is deprecated and can be replaced withrender
.
Installation
You can install the package via composer:
Usage
Create a new environment factory instance:
Then create a new template instance parsing a liquid template:
And finally render the template:
For advanced use cases, you can also stream the rendering output (still experimental):
Drops
Liquid support almost any kind of object but in order to have a better control over the accessible data in the templates,
you can pass your data as Drop
objects and have a better control over the accessible data.
Drops are standard php objects that extend the Keepsuit\Liquid\Drop
class.
Public properties and public methods of the class will be accessible in the template as a property.
You can also override the liquidMethodMissing
method to handle undefined properties.
Liquid provides some attributes to control the behavior of the drops:
Hidden
: Hide the method or the property from the template, it cannot be accessed from liquid.Cache
: Cache the result of the method, it will be called only once and the result will be stored in the drop.
If you implement the MapsToLiquid
interface in your domain classes,
the liquid renderer will automatically convert your objects to drops.
Advanced usage
Custom tags
To create a custom tag, you need to create a class that extends the Keepsuit\Liquid\Tag
abstract class (or Keepsuit\Liquid\TagBlock
if tag has a body).
[!NOTE] Take a look at the implementation of default tags to see how to implement
parse
andrender
methods.
Then you need to register the tag in the environment:
Custom filters
To create a custom filter, you need to create a class that extends the Keepsuit\Liquid\Filters\FiltersProvider
abstract class.
Each public method of the class will be registered as a filter.
You can "hide" a public method with the Hidden
attribute, so it will not be registered as filter.
Then you need to register the filters provider in the environment:
Extensions
Extensions allow you to add custom tags, filters, and other features to the liquid environment.
To create a custom extension, you need to create a class that extends the Keepsuit\Liquid\Extensions\Extension
abstract class.
Then you need to register the extension in the environment:
Custom tags and filters
By default, only the standard liquid tags and filters are available. But this package provides some custom tags and filters that you can use.
Tags
DynamicRender
: This tag replace the defaultRender
tag and allows to render dynamic templates (eg. read template name from a variable).
Filters
TernaryFilter
ternary
: adds a ternary operator.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- Shopify
- Fabio Capucci
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of liquid with dependencies
ext-mbstring Version *