mindkomm / timmy

Advanced image handling for Timber.
MIT License
171 stars 13 forks source link

Preserve the class attribute on fallback IMG in PICTURE #67

Closed sque89 closed 1 month ago

sque89 commented 9 months ago

When using <picture> some styles still need to be applied on the <img>. One example would be object-fit. So we need a way to provide a CSS class to the fallack <img> inside the picture to apply those styles to it.

This MR checks if a class attribute is available and if so, preserves it on the <img>.

Usage: post.thumbnail|get_timber_picture_responsive($image_size, {class: 'theClass'}) which will set the class attribute of <img> to theClass

sque89 commented 1 month ago

Hi @gchtr, do you think this can be merged anytime soon? Thanks a lot!

gchtr commented 1 month ago

@sque89 I added a test and documentation for this in #84 and merged it in.

I also renamed the argument from class to img_class. I did this because in the future, there might be a function that also adds the <picture> tag. There, we could also have a class argument and we would have to discern between the class for the <picture> and the class for the <img> tag.

gchtr commented 1 month ago

This is now released in https://github.com/mindkomm/timmy/releases/tag/v2.1.0.