API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...
Currently says:
variables: Only used for #theme in render array: an array of variables, where the array keys are the names of the variables, and the array values are the default values if they are not given in the render array. Template implementations receive each array key as a variable in the template file (so they must be legal PHP/Twig variable names). Function implementations are passed the variables in a single $variables function argument.
Could really do to explain that the variable name you define here is the name without the #, so that you have this system:
Defined in hook_theme():
'book_navigation' => array(
'variables' => array('book_link' => NULL),
),
Use in a render array:
$build['book_navigation'] = array(
'#theme' => 'book_navigation',
'#book_link' => $node->book,
Comments
Comment #2
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedComment #3
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedHere I tried to add the recommendation of @joachim including the sample implementation code.
Hope everything is in order.
Thanks!
Comment #4
jhodgdonThanks for the patch! But I think this is way more explanation than we need. Can we cut it down to just one sentence? Also please wrap it into the paragraph that is already there.
Comment #5
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedComment #6
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedThanks for the review! Here I have cut down the explanation following from what's on the issue description and just included the new explanation into the paragraph before it.
Comment #7
jhodgdonThanks, but...
Again, this is WAY more than I think we need.
How about just saying something like:
If you are using these variables in a render array, prefix the variable names defined here with a #.
I really don't think we need all these code samples...
Comment #8
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedComment #9
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedThanks for your feedback @jhodgdon! My bad on not getting the "this is WAY more than I think we need" part right away.
Here I have removed the code samples and followed your recommendation.
Comment #10
jhodgdonThat looks good to me. Thanks!
Comment #11
alexpottCommitted ba83d07 and pushed to 8.1.x and 8.2.x. Thanks!