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

jenlampton’s picture

Issue summary: View changes

add more fluff

jenlampton’s picture

Issue summary: View changes

related

jenlampton’s picture

Issue summary: View changes

rel

paranojik’s picture

Version: 7.21 » 8.x-dev

Just moving to the 8.x queue.

paranojik’s picture

Issue summary: View changes

less snark

joelpittet’s picture

Issue summary: View changes

I'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

star-szr’s picture

Title: Create drillable render arrays » Pass variables to Twig in a nicer way (was: Create drillable render arrays)
Version: 8.0.x-dev » 8.1.x-dev
Status: Active » Postponed
Related issues: +#2008450: Provide for a drillable variable structure in Twig templates

Adding 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.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

Status: Postponed » Closed (outdated)

Closing 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.