I’m using Grav v1.7.3 - Admin v1.10.2 and in the system config for media there’s a new option allowing us to choose a native loading type (auto, lazy, eager). That’s a really great enhancement!
Unfortunately I cannot make it work. More precisely, it works when I use the markdown syntax (adding “?loading=lazy” as an attribute in the md editor) but not when I use the twig “image.html()” function in a template. Am I missing something? Is there something else to do than choosing the “lazy” option in the system config?
@jordan, Haven’d found any documentation on it, but according the code you should be able to do the following in Twig:
{#
Gets default from 'system.images.defaults.loading'
Unfortunately not working currently due to [issue](https://github.com/getgrav/grav/issues/3192)
#}
{{ (page.media|first).loading.html() | raw }}
{# Workaround for above issue #}
{{ (page.media|first).loading(config.system.images.defaults.loading).html() | raw }}
{# Provide loading method #}
{{ (page.media|first).loading('lazy').html() | raw }}
In upgrade doc it’s written: Markdown: Added support for native loading=lazy attributes on images. Can be set in system.images.defaults or per md image with ?loading=lazy
I’ve set lazy option in Configuration -> Media -> Image loading behavior in admin area. But attributes was not applied to img tags. I had to change my md to this: {{ image.cropResize(806,582).loading.html }}
So, does this Can be set in system.images.defaults mean, that this option doesn’t work and loading should be set manually?
Or there is another use case scenario where it works without any chages in md code?
// HTML
<img loading="lazy" alt="" src="...">
<img loading="eager" alt="" src="...">
For Twig, the loading function must still be applied explicitly like {{page.media['myimage.jpg'].loading().html() | raw}}.
Without parameters, the default will be picked up.