node.twig

Default theme implementation to display a node.

Available variables:

  • label: the title of the node.
  • content: node items. Use {{ content }} to print them all, or print a subset such as {{ content.field_example }}. Use {% hide(content.field_example) %} to temporarily suppress the printing of a given element.
  • user_picture: The node author's picture from user-picture.twig.
  • date: Formatted creation date. Preprocess functions can reformat it by calling format_date() with the desired parameters on $variables['created'].
  • name: Themed username of node author output from theme_username().
  • node_url: Direct URL of the current node.
  • display_submitted: Whether submission information should be displayed.
  • submitted: Submission information created from name and date during template_preprocess_node().
  • attributes: HTML attributes for the surrounding element. Attributes include the 'class' information, which contains:

    • node: The current template type; for example, "theming hook".
    • node-[type]: The current node type. For example, if the node is a "Article" it would result in "node-article". Note that the machine name will often be in a short form of the human readable label.
    • view-mode-[view_mode]: The View Mode of the node; for example, "teaser" or "full".
    • preview: Nodes in preview mode.

    The following are controlled through the node publishing options.

    • promoted: Nodes promoted to the front page.
    • sticky: Nodes ordered above other non-sticky nodes in teaser listings.
    • unpublished: Unpublished nodes visible only to administrators.
  • title_prefix: Additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
  • title_suffix: Additional output populated by modules, intended to be displayed after the main title tag that appears in the template.

Other variables:

  • node: Fully loaded node entity.
  • type: Node type; for example, page, article, etc.
  • comment_count: Number of comments attached to the node.
  • uid: User ID of the node author.
  • created: Time the node was published formatted as a Unix timestamp.
  • zebra: Outputs either "even" or "odd". Useful for zebra striping in teaser listings.
  • id: Position of the node. Increments each time it's output.

Node status variables:

  • view_mode: View mode; for example, "teaser" or "full".
  • teaser: Flag for the teaser state. Will be true if view_mode is 'teaser'.
  • page: Flag for the full page state. Will be true if view_mode is 'full'.
  • promote: Flag for front page promotion state.
  • sticky: Flag for sticky post setting.
  • status: Flag for published status.
  • comment: State of comment settings for the node.
  • readmore: Flag for more state. Will be true if the teaser content of the node cannot hold the main body content.
  • is_front: Flag for front. Will be true when presented on the front page.
  • logged_in: Flag for authenticated user status. Will be true when the current user is a logged-in member.
  • is_admin: Flag for admin user status. Will be true when the current user is an administrator.

Field variables: for each field instance attached to the node a corresponding variable is defined; for example, $node->body becomes body. When needing to access a field's raw values, developers/themers are strongly encouraged to use these variables. Otherwise they will have to explicitly specify the desired field language; for example, $node->body['en'], thus overriding any language negotiation rule that was previously applied.

See also

template_preprocess()

template_preprocess_node()

File

drupal/core/modules/node/templates/node.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to display a node.
  5. *
  6. * Available variables:
  7. * - label: the title of the node.
  8. * - content: node items. Use {{ content }} to print them all,
  9. * or print a subset such as {{ content.field_example }}. Use
  10. * {% hide(content.field_example) %} to temporarily suppress the printing
  11. * of a given element.
  12. * - user_picture: The node author's picture from user-picture.twig.
  13. * - date: Formatted creation date. Preprocess functions can reformat it by
  14. * calling format_date() with the desired parameters on
  15. * $variables['created'].
  16. * - name: Themed username of node author output from theme_username().
  17. * - node_url: Direct URL of the current node.
  18. * - display_submitted: Whether submission information should be displayed.
  19. * - submitted: Submission information created from name and date during
  20. * template_preprocess_node().
  21. * - attributes: HTML attributes for the surrounding element.
  22. * Attributes include the 'class' information, which contains:
  23. * - node: The current template type; for example, "theming hook".
  24. * - node-[type]: The current node type. For example, if the node is a
  25. * "Article" it would result in "node-article". Note that the machine
  26. * name will often be in a short form of the human readable label.
  27. * - view-mode-[view_mode]: The View Mode of the node; for example, "teaser"
  28. * or "full".
  29. * - preview: Nodes in preview mode.
  30. * The following are controlled through the node publishing options.
  31. * - promoted: Nodes promoted to the front page.
  32. * - sticky: Nodes ordered above other non-sticky nodes in teaser
  33. * listings.
  34. * - unpublished: Unpublished nodes visible only to administrators.
  35. * - title_prefix: Additional output populated by modules, intended to be
  36. * displayed in front of the main title tag that appears in the template.
  37. * - title_suffix: Additional output populated by modules, intended to be
  38. * displayed after the main title tag that appears in the template.
  39. *
  40. * Other variables:
  41. * - node: Fully loaded node entity.
  42. * - type: Node type; for example, page, article, etc.
  43. * - comment_count: Number of comments attached to the node.
  44. * - uid: User ID of the node author.
  45. * - created: Time the node was published formatted as a Unix timestamp.
  46. * - zebra: Outputs either "even" or "odd". Useful for zebra striping in
  47. * teaser listings.
  48. * - id: Position of the node. Increments each time it's output.
  49. *
  50. * Node status variables:
  51. * - view_mode: View mode; for example, "teaser" or "full".
  52. * - teaser: Flag for the teaser state. Will be true if view_mode is 'teaser'.
  53. * - page: Flag for the full page state. Will be true if view_mode is 'full'.
  54. * - promote: Flag for front page promotion state.
  55. * - sticky: Flag for sticky post setting.
  56. * - status: Flag for published status.
  57. * - comment: State of comment settings for the node.
  58. * - readmore: Flag for more state. Will be true if the teaser content of the
  59. * node cannot hold the main body content.
  60. * - is_front: Flag for front. Will be true when presented on the front page.
  61. * - logged_in: Flag for authenticated user status. Will be true when the
  62. * current user is a logged-in member.
  63. * - is_admin: Flag for admin user status. Will be true when the current user
  64. * is an administrator.
  65. *
  66. * Field variables: for each field instance attached to the node a corresponding
  67. * variable is defined; for example, $node->body becomes body. When needing to
  68. * access a field's raw values, developers/themers are strongly encouraged to
  69. * use these variables. Otherwise they will have to explicitly specify the
  70. * desired field language; for example, $node->body['en'], thus overriding any
  71. * language negotiation rule that was previously applied.
  72. *
  73. * @see template_preprocess()
  74. * @see template_preprocess_node()
  75. *
  76. * @ingroup themeable
  77. */
  78. #}
  79. <article id="node-{{ node.nid }}" class="{{ attributes.class }} clearfix"{{ attributes }}>
  80. {{ title_prefix }}
  81. {% if not page %}
  82. <h2{{ title_attributes }}>
  83. <a href="{{ node_url }}" rel="bookmark">{{ label }}</a>
  84. </h2>
  85. {% endif %}
  86. {{ title_suffix }}
  87. {% if display_submitted %}
  88. <footer>
  89. {{ user_picture }}
  90. <p class="submitted">{{ submitted }}</p>
  91. </footer>
  92. {% endif %}
  93. <div class="content"{{ content_attributes }}>
  94. {# We hide the comments and links now so that we can render them later. #}
  95. {% hide(content.comments) %}
  96. {% hide(content.links) %}
  97. {{ content }}
  98. </div>
  99. {{ content.links }}
  100. {{ content.comments }}
  101. </article>

Related topics