There are several places where we revert to Drupal-7 style printing of ugly and incomprehensible variables in template files because we want attributes to be renderable, or renderables to be drillable.
<li{{ item['#wrapper_attributes'] }}>{{ item }}</li>
We need to rethink our approach a little to clean up these templates. There's two things here that are big no-nos for the new theme layer: the array-like syntax and also the hash in the key. It seems like we should be able to do something a little smarter with Twig (if we can't do it in render) to take care of attributes on items in loops.
The correct syntax should be
<li{{ item.attributes }}>{{ item }}</li>
Can't we do something to create 'attributes' at render time (if it doesn't already exist) by checking tem['#wrapper_attributes'] and generating attributes on the fly?
Related:
#1828536: Rename 'type' variable of theme_item_list() to 'list_type'
#891112: Replace theme_item_list()'s 'data' items with render elements
#1939062: Convert theme_item_list() to Twig
Comments
Comment #0.0
jenlamptonadd more fluff
Comment #0.1
jenlamptonrelated
Comment #0.2
jenlamptonrel
Comment #1
paranojik CreditAttribution: paranojik commentedJust moving to the 8.x queue.
Comment #1.0
paranojik CreditAttribution: paranojik commentedless snark
Comment #2
joelpittetI've been trying to remove these as much as possible and so far we've been winning! So could you point out any remaining or maybe this issue can be closed?
Last won battle that I remember was here #1939062: Convert theme_item_list() to Twig
Comment #3
star-szrAdding a related issue and bumping. This one is more actionable than the related issue IMO but at the same time may be hard to do in a backwards compatible manner.
Comment #6
joelpittetClosing this since we don't have that in core, most variables don't use
['#key']
syntax and are passed through as variables or object properties.I made some headway but nothing in an actual issue with wrapping render arrays in a
ArrayObject
with a__get()
to access the properties which worked pretty good but PHP has the same issues we had with Attributes object conversion where you can't create new objects with array values.