The Liquid engine we use to render themes on YouCan. If you're building a theme, you probably want the theme docs instead.
composer require youcanshop/liquidNeeds PHP 8.0+.
use YouCan\Liquid\Template;
$template = new Template();
$template->parse('Hello, {{ customer.name }}!');
echo $template->render(['customer' => ['name' => 'Ada']]);Custom tags and filters:
$template->registerTag('section', SectionTag::class);
$template->registerFilter('money', fn($amount) => number_format($amount, 2));Drops are objects whose fields only load when a template reads them:
use YouCan\Liquid\Drop;
class ProductDrop extends Drop
{
public function __construct(private Product $product) {}
public function name(): string
{
return $this->product->name;
}
public function reviews(): array
{
return Review::forProduct($this->product->id);
}
}For dynamic keys (e.g. a lookup by handle) override hasKey() and invokeDrop().
firstandlastwork mid-path:collection.products.first.name- quoted, numeric and variable keys:
collections['all'],products[0],all_products[handle] map,sortandwhereread drop fields- drops are always truthy, and compare by value when they implement
JsonSerializable
composer test
vendor/bin/php-cs-fixer fix --dry-run --diffTo release, run ./release.sh -p (or -m, -M), then create the GitHub release for the new tag with gh release create <tag> --generate-notes.
Originally based on kalimatas/php-liquid.
MIT