Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Lazy load img tag
Hi all!
My request is to be able to output lazy load within an image or thumb output tag:
eg. txp:thumbnail id=“298” loading=“lazy”
Would be super handy!
…………………
I <3 txp
…………………
Offline
Offline
Re: Lazy load img tag
etc wrote #330270:
Hi Hilary! Would it? It is, since 4.8.something.
Ooo does it work within the tag!? Thanks! :)
…………………
I <3 txp
…………………
Offline
Re: Lazy load img tag
etc wrote #330270:
Hi Hilary! Would it? It is, since 4.8.something.
Ye are way ahead of me and not for the first time :D
…………………
I <3 txp
…………………
Offline
Offline
Re: Lazy load img tag
It is handy but only (currently) works in the individual image tags. Using it in <txp:images>
would require passing that attribute forward to all the tags in the form/container (i.e. setting a globa flagl) so they all have the attribute set by default. At the individual tag level, it then needs to be possible to override the global flag as set in the wrapper.
Code-wise that’s all pretty grungy so we’ve left it at the tag level for now. And if you’re using a form or container, you usually only have one or two <txp:image>
or <txp:thumbnail>
tags inside it anyway, so it’s not much extra work to add the loading
attribute there.
Hope it’s helpful as it is.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Lazy load img tag
Bloke wrote #330274:
It is handy but only (currently) works in the individual image tags.
My memory is even worse than I thought, thanks for the reminder.
And if you’re using a form or container, you usually only have one or two
<txp:image>
or<txp:thumbnail>
tags inside it anyway, so it’s not much extra work to add theloading
attribute there.
And if you have many manually added images inside Body
(and are lazy, unlike the images), a quick-n-dirty trick should do:
<txp:body trim="<img" replace='<img loading="lazy"' />
Offline
Re: Lazy load img tag
Brilliant tips, thanks all!! :)
…………………
I <3 txp
…………………
Offline
Pages: 1