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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package liquid

PHP implementation of Liquid markup language

Latest Version on Packagist Tests Total Downloads

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:

Shopify Liquid version compatibility

PHP Liquid Shopify Liquid
v0.11 - v0.12 v5.13
v0.10 v5.12
v0.9 v5.8
v0.8 v5.7
v0.7 v5.6
v0.1 - v0.6 v5.5

Differences from Shopify Liquid

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):

Compiled templates

Compilation is opt-in. For production, use CompiledTemplatesCache to compile named templates on cache misses and load PHP artifacts on subsequent disk hits:

The first miss returns a parsed template; disk hits return a compiled template. With keepInMemory: true (the default), compiled templates stay in memory for the cache instance once loaded; templates written on a miss are loaded by the next hit. Use remove($name) or clear() when templates change or the library is upgraded. For manual artifact management, call Environment::compile($parsedTemplate, $path) and load the result with require $path.

Loaded artifacts also support stream(). Compiled artifact classes remain loaded for the lifetime of a long-running worker.

Custom CanBeCompiled nodes should throw Keepsuit\Liquid\Compiler\UnsupportedNodeException to request runtime fallback. Any other exception aborts compilation. Generated yields must go through CompilerContext::writeYield(), not write('yield ...').

Output formatting

Float output follows Shopify Liquid 5.13: integral floats keep .0 ({{ 2 | times: 1.5 }} renders 3.0), other floats use the shortest decimal representation that round-trips, with Ruby-style scientific notation, -0.0, Infinity, -Infinity and NaN. Formatting relies on PHP's default serialize_precision (-1) and does not depend on the numeric locale. Like Shopify, plus, minus, times, divided_by, modulo and sum compute in decimal arithmetic on floats' shortest representation: {{ 0.0725 | times: 100 }} renders 7.25.

tablerow follows Shopify's HTML whitespace: a newline after the first <tr>, adjacent cells, \n between rows and after the final </tr>. Whitespace-control markers on raw delimiters trim only the surrounding text: {%- raw -%} a {%- endraw -%} renders a.

Compatibility change: float strings and tablerow HTML differ from earlier releases. Prices, string conversions and exact-output snapshots may need updating.

Date formatting

The date filter uses Ruby-style strftime directives: only % directives are formatted, other text is literal (date: 'Day %d at %H' produces Day 05 at 14). Day and month names are always English. Values that cannot be parsed as a date (including floats and booleans) are returned unchanged, without errors.

Numeric filters

Standard numeric filters use Liquid coercion: nil, booleans and non-numeric strings become zero; strings can supply a leading integer prefix ('1abc' | plus: 1 produces 2). Integer division rounds down, and modulo follows the divisor's sign, including for floats. Float division by zero produces Infinity, -Infinity or NaN; integer division by zero remains a Liquid error.

These conversions also apply with strictVariables and strictFilters enabled. Missing variables still report an error under strictVariables; strictFilters controls unknown filter names. rethrowErrors controls error propagation, and lazyParsing controls loading partials during rendering. Custom filters retain their own parameter types. Arithmetic uses PHP's native integer and float precision.

String and HTML filters

Standard string and HTML filters use the shared Liquid string coercion: booleans become true/false and nil becomes an empty string. Supplied string arguments use the same conversion. Optional arguments follow the filter's defaults (replace and replace_first default to an empty replacement); required arguments remain required. Integer arguments use Liquid integer validation.

split with ' ' splits whitespace runs, with '' splits multibyte characters, and otherwise drops trailing empty fields. slice accepts an offset of -size. truncatewords ignores leading whitespace when counting words and preserves the original input when no truncation is needed.

escape, its alias h, and escape_once encode only & < > " ', using &#39; for apostrophes. strip_html removes multiline script/style blocks and comments. URL-safe Base64 filters are available; encoding includes padding, while decoding accepts omitted padding and rejects malformed encodings. Standard Base64 decoding requires correctly padded input.

These conversions also apply with strict options enabled. Missing variables still report errors under strictVariables, unknown filters follow strictFilters, and rethrowErrors controls propagation. lazyParsing only controls partial loading. Custom filters retain their own parameter types. The shared string coercion supports scalars and Stringable objects; arrays and other objects become empty strings rather than Ruby-style representations.

Array filters

Standard array filters accept nil, scalars, lists, hashes, and iterators. Filters using a collection flatten nested PHP lists, preserve associative arrays as hashes, and bind drops to the current context. An empty PHP array is a list, so nested empty arrays disappear during flattening. Iterator entries retain their structure. first, last, and size preserve the original collection shape; first on a hash returns its first key/value pair, while last returns nil. Hash lookups retain their existing key-based behavior; use the explicit first filter for a pair. On integers, size returns the native integer byte size, as in Ruby.

map retains arrays returned by properties; a subsequent join flattens them. concat flattens its input but keeps the appended array's structure and requires an array argument. join uses Liquid string conversion, including boolean names, float types, and Ruby-style hash representations. sum uses the shared numeric coercion, including leading numeric prefixes.

uniq preserves the first occurrence and distinguishes integers, floats, strings, and booleans. Hashes compare by content regardless of key order, and drops compare by identity unless they expose a Liquid value. compact removes only nil. Without a target, where, reject, has, find, and find_index treat only nil and false as falsy; with a target they use condition equality. sort rejects incompatible types with a Liquid argument error; sort_natural compares strings case-insensitively.

These rules apply with strict options enabled. Missing variables still follow strictVariables, unknown filters follow strictFilters, and rendering errors follow the configured handler or rethrowErrors. lazyParsing only controls partial loading, and parsing remains strict. Custom filters retain their parameter types.

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:

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 and render 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:

Templates cache

By default parsed templates are kept in a MemoryTemplatesCache, which lasts as long as the PHP process, so with PHP-FPM every request parses the templates again. SerializeTemplatesCache and VarExportTemplatesCache store parsed templates on disk; CompiledTemplatesCache stores executable PHP artifacts. With keepInMemory: true (the default) each template is read from disk only once per cache instance.

VarExportTemplatesCache requires symfony/var-exporter.

Resource limits

Keepsuit\Liquid\Render\ResourceLimits supports both per-render limits and cumulative resource limits.

Per-render counters can be reset between renders. Cumulative counters are intended for a full render lifecycle so repeated partial renders can share the same budget.

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

Filters

Testing

This runs the full suite twice, using in-memory and compiled templates with the same expected outputs. Rendering helpers compile roots and partials, including partials loaded lazily. Parser, AST and serialized-cache tests retain their parsed fixtures; compiler-specific tests continue to exercise their explicit backends. Streaming output comparisons concatenate chunks when their boundaries are not part of the test.

To run a single backend:

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of liquid with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-mbstring Version *
brick/math Version ^0.14.3 || ^0.15 || ^0.16 || ^0.17 || ^0.18 || ^0.19 || ^0.20 || ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package keepsuit/liquid contains the following files

Loading the files please wait ...