diff --git a/themes/bartik/templates/node.tpl.php b/themes/bartik/templates/node.tpl.php index f215b47..994c19c 100644 --- a/themes/bartik/templates/node.tpl.php +++ b/themes/bartik/templates/node.tpl.php @@ -4,20 +4,23 @@ * @file * Bartik's theme implementation to display a 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. + ****************** + * Basic variables: + ****************** + * + * The following variables contain HTML-safe strings which can be printed in + * the template file using a syntax like + * + * - $title: The title of the node. * - $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(). + * template_preprocess_node(). Only print this when the $display_submitted + * variable is TRUE, since otherwise the site administrator has requested + * that it not be displayed. * - $classes: String of classes that can be used to style contextually through * CSS. It can be manipulated through the variable $classes_array from * preprocess functions. The default values can be one or more of the @@ -33,16 +36,110 @@ * - node-sticky: Nodes ordered above other non-sticky nodes in teaser * listings. * - node-unpublished: Unpublished nodes visible only to administrators. - * - $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 + * + * Some of the most important variables required to theme the node are provided + * as renderable arrays (in the "Advanced variables" section below), for + * maximum flexibility in the theming layer. For convenience, however, we + * define basic variables here based on the way we want to render these arrays + * in this particular template file. As above, these all contain HTML-safe + * strings which can be printed in the template file using a syntax like + * + * + * - $title_prefix_html: HTML that is populated by modules and intended to be + * displayed in front of the main title tag that appears in the template. + * (This is a rendered version of the $title_prefix array, which can be found + * in the "Advanced variables" section below.) + * - $title_suffix_html: HTML that is populated by modules and intended to be + * displayed after the main title tag that appears in the template. (This is + * a rendered version of the $title_suffix array, which can be found in the + * "Advanced variables" section below.) + * - $comments_html: HTML containing the comments associated with the node. + * - $links_html: HTML containing the links associated with the node, such as a + * "Read more" link. + * - $content_html: HTML containing the rendered content of the node, excluding + * the comments and links. (This and the variables above it are rendered from + * the $content array, which can be found in the "Advanced variables" section + * below.) + * + **************** + * Boolean flags: + **************** + * + * The following variables can only take on true/false values and are often + * used in the template file with a syntax like: + * + * ... + * + * to decide whether or not other variables or HTML should be printed. + * + * - $teaser: Flag for the teaser state. + * - $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. + * - $display_submitted: Flag for whether submission information (contained in + * the $submitted variable) should be displayed. + * - $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. + * + ********************* + * Advanced variables: + ********************* + * + * The following variables contain renderable arrays which can be printed in + * the template file using a syntax like . To + * print part of the array's content without touching the rest, use a syntax + * like . To temporarily suppress + * the printing of a given element, use . + * + * - $content: An array of node items making up the main content of the node. + * - $title_prefix: 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: An array containing additional output populated by modules, + * intended to be displayed after the main title tag that appears in the + * template. + * + * For the specific needs of this template file, these variables are rendered + * in a particular way, and the resulting HTML strings are stored in new + * variables (listed in the "Basic variables" section above) which are then + * printed to the template file directly. The PHP code below shows how this is + * done and can be modified for more advanced use cases (e.g., if you want to + * render the variables differently). + * + *****************************************************************************/ + // PHP code to prepare the variables described above. + // This is used for the limited purpose of defining simple, easy-to-print + // variables that are specific to this template and derived from the + // renderable arrays provided to us. In general, PHP code to add new + // variables or for more advanced use cases belongs in a preprocess function + // in the theme's template.php file, e.g. bartik_preprocess_node(), rather + // than here. + $title_prefix_html = render($title_prefix); + $title_suffix_html = render($title_suffix); + $comments_html = render($content['comments']); + // Remove the "Add new comment" link on the teaser page or if the comment + // form is being displayed on the same page. + if ($teaser || !empty($content['comments']['comment_form'])) { + unset($content['links']['comment']['#links']['comment-add']); + } + $links_html = render($content['links']); + $content_html = render($content); +/****************************************************************************** * + ****************** * Other variables: + ****************** + * + * The following variables are less commonly used. + * * - $node: Full node object. Contains data that may not be safe. * - $type: Node type, i.e. story, page, blog, etc. + * - $view_mode: The node's view mode, e.g. 'full', 'teaser'... * - $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. @@ -52,23 +149,13 @@ * teaser listings. * - $id: Position of the node. Increments each time it's output. * - * Node status variables: - * - $view_mode: View mode, e.g. '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. + ****************** + * Field variables: + ****************** * - * Field variables: for each field instance attached to the node a corresponding - * variable is defined, e.g. $node->body becomes $body. When needing to access - * a field's raw values, developers/themers are strongly encouraged to use these + * For each field instance attached to the node a corresponding variable is + * defined, e.g. $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, e.g. $node->body['en'], thus overriding any language negotiation * rule that was previously applied. @@ -80,13 +167,13 @@ ?>
> - + > - +