Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For the image template, every variable is actually an attribute: src, title, alt, class, width, height, etc. Do any of these attributes need special treatment? If we treat them all as standard attributes our image template file could end up looking like this:
<img {{ attributes }} />
Is that alright? Or do we want to pull out src and treat it specially? any others we should worry about?
Comment | File | Size | Author |
---|---|---|---|
#12 | d8tts-theme-image-1643894-12.patch | 3.83 KB | steveoliver |
#9 | d8tts-theme-image-1643894-9.patch | 3.77 KB | steveoliver |
#7 | d8tts-image-template-1643894-7.patch | 3.77 KB | steveoliver |
Comments
Comment #1
JohnAlbinI definitely don't think we need to treat src specially. The reason's to tweak that are so edge-case that we should just let them figure out how to pull it out using twig syntax themselves.
And I can't really think of any other attributes we'd need.
Comment #2
jenlamptonAlright :) great!
So then the TODO here is to merge all the current vars for this template file into attributes before it gets to the template, then we can just print them all out as attributes.
FYI - just so I'm not committing something totally broken, the code for this template looks like this right now:
Comment #3
jenlamptonupdating the title :)
Comment #4
davidneedhamIt seems very unusual, but I also agree that the reasons to tweak are few and far between.
Comment #5
jenlamptonAs a follow up here, we did decide to treat class specially, so the template looks like this:
Also. moving this to the active twig sandbox.
Comment #7
steveoliver CreditAttribution: steveoliver commentedThe image template still needs some love. Patch attached.
Comment #8
steveoliver CreditAttribution: steveoliver commentedStill wondering about this format. ... for theme('whatever') seems to make the most sense to me.
Comment #9
steveoliver CreditAttribution: steveoliver commentedHi-jacking this thread because there doesn't seem to be one about theme('image') and what else is there but a bunch of attributes. Can I get an RTBC? ;)
Also, comment about preprocess docblock titles is at #1825464: [meta] Documentation blocks for preprocess functions.
Comment #10
podarok*/
#}
looks like this image has no src to image.extension itself
Comment #11
Fabianx CreditAttribution: Fabianx commentedThe ?: might seem clever here, but achieves nothing as:
* this will create a notice if attributes is not set
* this will resolve to array() if $variables['attributes'] is null or empty.
Such this statement is equivalent to:
What you want is the long form of:
isset($x)?$x:array()
Thanks!
Comment #12
steveoliver CreditAttribution: steveoliver commented1.
2. src is an attribute, so I put it in attributes.src, which would have printed with this:
...but is a little easier to look at this way, I suppose:
Comment #13
podarok#12 commited / pushed to front-end
thanks!
looks like we need follow-up here for TODO in template
Comment #14
joelpittetLooks as though the TODO has been fixed in front-end - marking as fixed