There are still quite a few instances of variables prefixed with dollar signs (18 across 12 files, inside the stark/templates folder, to be exact).
I think we need to somehow work this documentation into a php-neutral format to reduce confusion and conflicting notations.
In general this raises the question of how do we denote a variable, when talking about it in the scope of a paragraph, when twig doesnt use a dollar sign.
Here is the output of my search:
Searching 145 files for " \* .*\$\w" (regex) in core/themes/stark/templates
core/themes/stark/templates/block/block.html.twig:
22 * Helper variables:
23 * - block_id: Counter dependent on each block region.
24: * - id: Same output as $block_id but independent of any block region.
25 * - is_front: Flags true when presented in the front page.
26 * - logged_in: Flags true when the current user is a logged-in member.
core/themes/stark/templates/comment/comment-wrapper.html.twig:
6 * Available variables:
7 * - content: The array of content-related elements for the node. Use
8: * render_var($content) to print them all, or print a subset such as
9: * render_var($content['comment_form']).
10 * - attributes: Remaining html attributes for the containing element.
11 * It includes the 'class' information, which includes:
core/themes/stark/templates/filter/filter-guidelines.html.twig:
8 * - attributes: Remaining html attributes for the containing element.
9 * - tips: Descriptions and a CSS id in the form of 'module-name/filter-id'
10: * (only used when $long is TRUE) for each filter in one or more text
11 * formats.
12 *
core/themes/stark/templates/filter/filter-tips.html.twig:
6 * Available variables:
7 * - tips: Descriptions and a CSS id in the form of 'module-name/filter-id'
8: * (only used when $long is TRUE) for each filter in one or more text
9 * formats.
10 * - long: (optional) Whether the passed-in filter tips contain extended
core/themes/stark/templates/forum/forum-topic-list.html.twig:
9 * template_preprocess_forum_topic_list().
10 * - pager: The pager to display beneath the table.
11: * - topics: An array of topics to be displayed. Each $topic in $topics
12 * contains:
13 * - topic.icon: The icon to display.
core/themes/stark/templates/image/image-rotate-summary.html.twig:
4 * Returns HTML for a summary of an image rotate effect.
5 *
6: * @param $variables
7 * - summary: The current configuration for this rotate effect.
8 *
core/themes/stark/templates/node/node.html.twig:
13 * - user_picture: The node author's picture from user-picture.html.twig.
14 * - created: Formatted creation date. Preprocess functions can reformat it by
15: * calling format_date() with the desired parameters on the $created variable.
16 * - changed: Formatted last-changed date.
17 * - node_url: Direct URL of the current node.
..
49 * Node status variables:
50 * - view_mode: View mode; for example, "teaser" or "full".
51: * - teaser: Flag for the teaser state (shortcut for $view_mode == 'teaser').
52 * - page: Flag for the full page state.
53 * - promote: Flag for front page promotion state.
..
62 *
63 * Field variables: for each field instance attached to the node a corresponding
64: * variable is defined; for example, $node->body becomes body. When needing to
65 * access a field's raw values, developers/themers are strongly encouraged to
66 * use these variables. Otherwise they will have to explicitly specify the
67: * desired field language; for example, $node->body['en'], thus overriding any
68 * language negotiation rule that was previously applied.
69 *
core/themes/stark/templates/system/html.html.twig:
15 * tag.
16 * - head_title_array: (array) An associative array containing the string parts
17: * that were used to generate the $head_title variable, already prepared to be
18 * output as TITLE tag. The key/value pairs may contain one or more of the
19 * following, depending on conditions:
core/themes/stark/templates/theme.inc/datetime.html.twig:
6 * - timestamp: (optional) A UNIX timestamp for the datetime attribute. If the
7 * datetime cannot be represented as a UNIX timestamp, use a valid datetime
8: * attribute value in $variables['attributes']['datetime'].
9 * - text: (optional) The content to display within the <time> element. Set
10 * 'html' to TRUE if this value is already sanitized for output in html.
core/themes/stark/templates/theme.inc/link.html.twig:
14 * array; 'title' must be a string; other elements are more flexible,
15 * as they just need to work in a call to
16: * drupal_attributes($options['attributes']).
17: * - options.html (default FALSE): Whether $text is html or just plain-text.
18 * For example, to make an image tag into a link, this must be set to
19 * TRUE, or you will see the escaped html image tag. text is not
..
21 * text is already safe.
22 * - options.language: An optional language object. If the path being
23: * linked to is internal to the site, $options['language'] is used to
24 * determine whether the link is "active", or pointing to the current
25 * page (the language as well as the path must match). This element is
core/themes/stark/templates/theme.inc/links.html.twig:
17 * included, it must be an array of one or more class names.
18 * If the 'href' element is supplied, the entire link array is passed to l()
19: * as its $options parameter.
20 * - attributes: attributes for the UL containing the
21 * list of links.
core/themes/stark/templates/user/username.html.twig:
11 * - link_path: The path or URL of the user's profile page, home page,
12 * or other desired page to link to for more information about the user.
13: * - link_options: An array of options to pass to the l() function's $options
14 * parameter if linking the user's name to the user's page.
15 * - attributes: An array of attributes if not linking to the user's page.
18 matches across 12 files
Comments
Comment #1
steveoliver commentedIn Twig coding standards, we've got a note about not using dollar signs or {{ print statements around variable names in Twig template.
Dollar signs (and instructions to use drupal_render()) are in these cases a telling sign that the templates came as conversions from theme_ functions, and that there docblocks were copied directly with minimal or no thoughtful conversion/adaptation of docblocks.
It looks like you're on it, jwilson3 ;)
Comment #2
steveoliver commentedSorry, to answer your question about referencing variables in-line in paragraphs, there is currently no suggestion in the Coding standards doc. I'm inclined to try (see if it makes sense) wrapping those in single quotes, if anything. What do you think?
Comment #3
jwilson3Wrapping references to variables in single quotes in the context of a paragraph inside a docblock, works for me. Thanks steve.
Comment #4
jenlamptonI love the idea of single quotes for in-line variable references. I noticed that the coding standards doc had not yet been updated, so I added a new paragraph there.
We'll also need to get rid of any references to the data type (object, array or string) since that won't matter anymore in D8.
Can we get a patch for this issue too? :)