Skip to content

Move srcset generation from Twig to Resolver - #173

Merged
xavierlacot merged 7 commits into
mainfrom
feature/81-srcset-builder
Sep 25, 2026
Merged

xavierlacot merged 7 commits into
mainfrom
feature/81-srcset-builder

Conversation

@xavierlacot

Copy link
Copy Markdown
Member

fix #81

This PR moves the srcset generation from the Twig components into a new SrcsetBuilder service, so it can also be used outside of Twig, for instance in an API Platform normalizer. It is also exposed through a new joli_media_srcset Twig filter.

The joli:Img component now builds the srcset of a variation configured with several pixel_ratios from its name alone, instead of requiring the derived variations to be listed by hand. This can be disabled with autoSrcset="{{ false }}".

When a variation has not been generated yet, its dimensions are now computed from the variation definition, so the srcset keeps its width descriptors and the img tag its width and height, even on a cold cache. Pre-processors declare whether they preserve the pixel dimensions with the new PreProcessorInterface::preservesPixelDimensions() method.

Also, the Twig components now read the dimensions from the cached property accessors instead of loading the whole variation file, and the properties of a missing file are no longer cached for a whole day.

@xavierlacot xavierlacot changed the title Feature/81 srcset builder Move srcset generation from Twig to Resolver Sep 21, 2026
@xavierlacot
xavierlacot force-pushed the feature/81-srcset-builder branch from cbe476e to 07503f2 Compare September 25, 2026 10:40
@xavierlacot
xavierlacot merged commit 1366d72 into main Sep 25, 2026
10 checks passed
@xavierlacot
xavierlacot deleted the feature/81-srcset-builder branch September 25, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move srcset generation from Twig to Resolver

1 participant