principales variables de page, node et block.tpl.php

La ref : https://api.drupal.org/api/drupal/modules!system!page.tpl.php/7 - https://api.drupal.org/api/drupal/modules!node!node.tpl.php/7 et https://api.drupal.org/api/drupal/modules!block!block.tpl.php/7
Setting up variables for use in a template (preprocess and process functions)

 

Quelques extraits:

template page

général:

  • $base_path: The base URL path of the Drupal installation. At the very least, this will always default to /.
  • $directory: The directory the template is located in, e.g. modules/system or themes/bartik.
  • $is_front: TRUE if the current page is the front page.
  • $logged_in: TRUE if the user is registered and signed in.
  • $is_admin: TRUE if the user has permission to access administration pages.

Page content (in order of occurrence in the default page.tpl.php):

  • $title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
  • $title: The page title, for use in the actual HTML content.
  • $title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
  • $messages: HTML for status and error messages. Should be displayed prominently.
  • $tabs (array): Tabs linking to any sub-pages beneath the current page (e.g., the view and edit tabs when displaying a node).
  • $action_links (array): Actions local to the page, such as 'Add menu' on the menu administration interface.
  • $feed_icons: A string of all feed icons for the current page.
  • $node: The node object, if there is an automatically-loaded node associated with the page, and the node ID is the second argument in the page's path (e.g. node/12345 and node/12345/revisions, but not comment/reply/12345).

Regions:

  • $page['help']: Dynamic help text, mostly for admin pages.
  • $page['highlighted']: Items for the highlighted content region.
  • $page['content']: The main content of the current page.
  • $page['sidebar_first']: Items for the first sidebar.
  • $page['sidebar_second']: Items for the second sidebar.
  • $page['header']: Items for the header region.
  • $page['footer']: Items for the footer region.

node

Available variables:

  • $title: the (sanitized) title of the node.
  • $content: An array of node items. Use render($content) to print them all, or print a subset such as render($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.tpl.php.
  • $date: Formatted creation date. Preprocess functions can reformat it by calling format_date() with the desired parameters on the $created variable.
  • $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().
  • $classes: String des classes qu'on peux utiliser pour mise en forme CSS. Manipulable via la variable $classes_array des fonctions preprocess.
    Les valeurs par défaut peuvent etre une (ou plus) parmi:
    • node: The current template type; for example, "theming hook".
    • node-[type]: The current node type. For example, if the node is a "Blog entry" it would result in "node-blog". Note that the machine name will often be in a short form of the human readable label.
    • node-teaser: Nodes in teaser form.
    • node-preview: Nodes in preview mode
    Ces var sont controlées via les options de publication du node: node-promoted node-sticky et node-unpublished
  • $title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
  • $title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.

Other variables:

  • $node: Full node object. Contains data that may not be safe.
  • $type: Node type; for example, story, page, blog, etc.
  • $comment_count: Number of comments attached to the node.
  • $uid: User ID of the node author.
  • $created: Time the node was published formatted in Unix timestamp.
  • $classes_array: Array of html class attribute values. It is flattened into a string within the variable $classes.
  • $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, "full", "teaser".
  • $teaser: Flag for the teaser state (shortcut for $view_mode == 'teaser').
  • $page: Flag for the full page state.
  • $promote: Flag for front page promotion state.
  • $sticky: Flags for sticky post setting.
  • $status: Flag for published status.
  • $comment: State of comment settings for the node.
  • $readmore: Flags true if the teaser content of the node cannot hold the main body content.
  • $is_front: Flags true when presented in the front page.
  • $logged_in: Flags true when the current user is a logged-in member.
  • $is_admin: Flags true when the current user is an administrator.

Var des champs: pour chaque instance de champ attaché à un node, il existe une var correspondante (ex: pour $node->body on a la var $body). Pour accéder aux données brutes du chp, le dev doit utiliser ces var, ou bien spécifier la langue (ex: $node->body['en'] override les règles de négotiation de langue).

block.tpl.php

  • $block->subject: Block title.
  • $content: Block content.
  • $block->module: Module that generated the block.
  • $block->delta: An ID for the block, unique within each module.
  • $block->region: The block region embedding the current block.
  • $classes: String des classes qu'on peux utiliser pour mise en forme CSS. Manipulable via la variable variable $classes_array des fonctions preprocess. Les valeurs par défaut peuvent etre une (ou plus) parmi :
    • block: The current template type, i.e., "theming hook".
    • block-[module]: The module generating the block. For example, the user module is responsible for handling the default user navigation block. In that case the class would be 'block-user'.
  • $title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
  • $title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.

Helper variables:

  • $classes_array: Array of html class attribute values. It is flattened into a string within the variable $classes.
  • $block_zebra: Outputs 'odd' and 'even' dependent on each block region.
  • $zebra: Same output as $block_zebra but independent of any block region.
  • $block_id: Counter dependent on each block region.
  • $id: Same output as $block_id but independent of any block region.
  • $is_front: Flags true when presented in the front page.
  • $logged_in: Flags true when the current user is a logged-in member.
  • $is_admin: Flags true when the current user is an administrator.
  • $block_html_id: A valid HTML ID and guaranteed unique.
logo drush