Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: variables of node.tpl.php

Submitted by on September 20, 2011 – 12:48 amNo Comment

Sometimes you need to work with template of a page in your site (node.tpl.php) file to adjust design of your site. In this article, I would tell you about node.tpl.php variables. I will tell about main variables, additional variables and status variables for Drupal 6 and Drupal 5.

Drupal 6

The file isn’t responsible for how to show data (fully or in lists)

Main variables:

  • $title: node title (without HTML tags).
  • $content: node content. Status of $teaser variable shows is it a full content or a teaser.
  • $picture: avatar or user picture from theme_user_picture() function.
  • $date: formatted creation date (use $created variable if you want to change format with format_date() function).
  • $links: links of a node “Read more”, “Add a comment”, etc from theme_links() function.
  • $name: formatted author’s name from theme_user() function.
  • $node_url: full path to a node page.
  • $terms: formatted list of node taxonomy terms from theme_links() function.
  • $submitted: formatted info about node author and creation date from theme_node_submitted() function.
Additional variables
  • $node: full node object. Could contain dangerous data.
  • $type: node type i.e. story, page, blog etc.
  • $comment_count: number of comments to a node.
  • $uid: ID of a node author.
  • $created: creation date of a node in Unix timestamp format.
  • $zebra: shows “even” or “odd” – position of a node in lists. It is used to alternate colors of neighboring nodes.
  • $id: node position (order number) in lists.
Status variables
  • $teaser: TRUE for a teaser mode.
  • $page: TRUE for full display mode.
  • $promote: TRUE for “show on home” status.
  • $sticky: TRUE  for “anchor above lists” status.
  • $status: TRUE for “published” status.
  • $comment: comments settings for a node: disabled – 0. read only  – 1. read/write – 2.
  • $readmore: TRUE  if node teaser doesn’t include a full content.
  • $is_front: TRUE for a home page.
  • $logged_in: TRUE for authorized user.
  • $is_admin: TRUE  if current user is administrator.

Drupal 5

This template is used to show content of a site (full site content or in a form of a list). It could affect on $content variable output only.

Available variables

$content – full content, teaser in a form of a list.
$date – formatted date of a node creation.
$directory – full path to a folder of a current theme, for example, themes/garland or themes/garland/minelli.
$id – node ID.
$is_front – TRUE if current page is a home page.
$links – list of links of  a current node.
$main (4.6) – TRUE if a node appears as a list similar to a home page with teasers only. The variable is shortly used in Drupal 4.7 or higher.
$name – formatted author’s name with a link.
$node (object) – object of a node. To view all properties of a current object ($node), insert ‘print_r($node’ code into node.tpl.php);
$node_url – path to a page of a current node.
$page – TRUE if a current node appears on its own page.
$picture – HTML-code of a user avatar (if enabled).
$sticky – TRUE if status of a node is «Sticky at top of lists».
$submitted – HTML-code of an author and creation date (if enabled for a current node).
$taxonomy (array) – array of HTML-code of links to a current node taxonomy terms.
$teaser – TRUE if a node appears as a teaser.
$terms – HTML-code of all links to a current node taxonomy terms.
$title – node title.
$zebra – value that shows even or odd number of a node in a list.

Notes

How to print a list of all available variables?

Print variables array

print ‘<pre>';
print_r(get_defined_vars());
print ‘</pre>';

Print variables array with HTML marking.

print ‘<pre>';
print htmlspecialchars(print_r(get_defined_vars(), TRUE), ENT_QUOTES);
print ‘</pre>';

Default template for Drupal 5.x

<div id=”node-<?php print $node->nid; ?>” class=”node<?php if ($sticky) { print ‘ sticky'; } ?><?php if (!$status) { print ‘ node-unpublished'; } ?> clear-block”>
<?php print $picture ?>
<?php if ($page == 0): ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>”><?php print $title ?></a></h2>
<?php endif; ?>
<div class=”meta”>
<?php if ($submitted): ?>
<span class=”submitted”><?php print $submitted ?></span>
<?php endif; ?>
<?php if ($terms): ?>
<span class=”terms”><?php print $terms ?></span>
<?php endif;?>
</div>
<div class=”content”>
<?php print $content ?>
</div>
<?php
if ($links) {
print $links;
}
?>
</div>

Default template for Drupal 4.7

<div class=”node<?php if ($sticky) { print ” sticky”; } ?><?php if (!$status) { print ” node-unpublished”; } ?>”>
<?php if ($page == 0): ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>”><?php print $title ?></a></h2>
<?php endif; ?>
<?php print $picture ?>
<div class=”info”><?php print $submitted ?><span class=”terms”><?php print $terms ?></span></div>
<div class=”content”>
<?php print $content ?>
</div>
<?php if ($links): ?>
<?php if ($picture): ?>
<br class=’clear’ />
<?php endif; ?>
<div class=”links”><?php print $links ?></div>
<?php endif; ?>
</div>

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.