Problem/Motivation
We need to figure out how best to document the variables for theme templates. There are two main users of this documentation:
a) Themers -- they need to know what variables are available for theming, in the template itself.
b) Module/core developers -- they need to know what variables to put into their render arrays. For templates with preprocessing functions, this list of variables is not the same as the variables in the theme template itself.
Proposed resolution
Probably the templates (either .html.twig or .tpl.php files, for Drupal 8 or 7) should have the variables that are available in the template itself, for themers.
What needs to be determined is where to document the variables that a module developer would need to put in their render array, and how a module developer would discover them.
Remaining tasks
Figure this out, write a standard, update Core to comply with it.
Original report....
It seems to me that the removal of theme functions in D8 has left a gap in our documentation, because there's no equivalent place to document how to use a theme hook.
For example, consider item_list.
On D7, the main documentation for this is https://api.drupal.org/api/drupal/includes!theme.inc/function/theme_item..., which tells you exactly what to pass in to a call to theme('item_list') or to a render array that uses #theme => item_list.
On D8, I don't think there is an equivalent.
There is https://api.drupal.org/api/drupal/core!modules!system!templates!item-lis..., but the documentation there tells you about the variables available to the template. In many cases, these will have been changed by the preprocess functions, so that's not always a correct guide on how to use the theme hook in a render array.
There's also https://api.drupal.org/api/drupal/core!includes!theme.inc/function/templ..., but that doesn't seem like an intuitive place to put the docs. Also, not every theme hook in core will have a preprocessor, so I wouldn't expect to find docs on how to use a theme hook here.
Comments
Comment #2
jhodgdonThe variables available to the module developer should be documented on the template if preprocessing is minimal, or on the (hopefully linked) preprocess function if not. This was also true in D7, when most of the theme functions were converted to tpl.php files.
In 8, most of these are elements and not #theme anyway... the few remaining places where you should actually use #theme and not #type should be documented on the templates.
If there are individual theme templates that need better docs, let's open individual issues to get them fixed.
Comment #3
joachim CreditAttribution: joachim as a volunteer commented> documented on the template if preprocessing is minimal, or on the (hopefully linked) preprocess function if not.
But that means that the place where you find how to use them is inconsistent.
And when the preprocessor function doesn't touch a particular variable at all, that tends to not get documented there.
Comment #4
joachim CreditAttribution: joachim as a volunteer commentedIt's not just me who has this concern -- from #2620854: links.html.twig docs are out of date:
Comment #5
jhodgdonOK, well if it's a real problem, it seems like what we need to do is file an issue in Coding Standards and agree to a standard. Then we can fix Core to comply with it. Postponing this issue until that process is done.
Comment #6
joachim CreditAttribution: joachim as a volunteer commentedLet's make this issue the coding standards issue, as my intention in filing it was to discuss how we deal with this.
Comment #7
jhodgdonUpdating title and summary
Comment #8
joachim CreditAttribution: joachim as a volunteer commentedI could have sworn I also filed an issue about how there's a problem with how to refer to theme elements now that theme_foo() functions don't exist.
But in the absence of that, here will do.
Even core doesn't know how to do this!