rolandtoth / MarkupSrcSet

Generate srcset markup with ease in ProcessWire CMS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request: keep order of srcsetUrls

phlppschrr opened this issue · comments

It would be nice if there would be a way get the $img->srcsetUrls array in the same order as defined in the $img->srcset('900,*2,/2') call.

Another suggestion would be to use 'smallest' and 'largest' instead of 'first'/'last'.
I forked your repo and implemented my suggestions here:
phlppschrr@71d30bc

Background to this request is, I want to use lazysizes like described here:
https://github.com/aFarkas/lazysizes#modern-transparent-srcset-pattern where it is recommended that the first image candidate in data-srcset matches the src fallback image.

With these changes I could do it like this:

<img
    data-srcset="<?= $img->srcset('900x0,*2,/2') ?>"
    src="<?= $img->srcsetUrls[0] ?>"
    srcset="<?= $config->srcsetFallbackDataUri ?>"
    alt="<?= $img->description ?>"
    data-sizes="auto"
    class="lazyload" />

v0.1.2 now works like this, thanks!