adhocore/twig-yall
It is a twig extension around malchata/yall.js
for lazy loading img
, picture
, video
, iframe
etc.
(Also supports source
tag and srcset
attribute).
Installation
composer require adhocore/twig-yall
Usage
First setup twig to register this extension:
// Use your loader of choice
$twig = new Twig\Environment(new Twig\Loader\ArrayLoader);
// Register Yall with defaults
$twig->addExtension(new Ahc\TwigYall\Yall);
// Configuring Yall instance:
$twig->addExtension(new Ahc\TwigYall\Yall(
'polyfillJs' => '<custom url to polyfill>',
'yallJs' => '<custom url to yall.js>',
'lazyClass' => '<default lazy class>',
'placeholder' => '<default placeholder image url>',
));
Voila, then in twig templates you would either use {% lazyload %}
block to lazyload whole block at once
OR individually lazyload each resources with {{ lazify() }}
.
…