Download the PHP package adhocore/twig-yall without Composer
On this page you can find all versions of the php package adhocore/twig-yall. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package twig-yall
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).
Eager loading of images and videos not only makes webpage slow and clumsy but also consumes a lot of bandwidth.
If you use twig templating system for your view layer, this extension defers loading of resources so they are loaded only when required in viewport.
Installation
Usage
First setup twig to register this extension:
Voila, then in twig templates you would either use {% lazyload %}
block to lazyload whole block at once
OR individually lazyload each resources with {{ lazify() }}
.
In both cases, you must call {{ yallify() }}
somewhere at the footer.
lazyload
With placeholder
config set to 'default.png'
, below template
will be rendered as:
lazify
only src
will be rendered as:
See stackoverflow for the usage of data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEAAAAALAAAAAABAAEAAAI=
.
with class
will be rendered as:
custom placeholder
will be rendered as:
video poster
will be rendered as:
source tag
will be rendered as:
src+srcset
will be rendered as:
yallify
Important: Do not forget to put the yall loader somewhere in the footer twig template:
Which by default loads yall 3.1.7 with polyfills. You can set yall.js version, and turn off polyfill like so:
You can pass yall options in third param. For event callbacks wrap it in <raw></raw>
:
will be rendered as:
PS:
The inputs sent to lazify()
or yallify()
are not validated by this library.
From malchata/yall.js
:
Use appropriate width and height attributes, styles, and lightweight placeholders for your images.
Contributing
Please check the guide
LICENSE
© MIT | 2019, Jitendra Adhikari