User login

Recent comments

How to see available template variables in Drupal

Drupal's phptemplate engine has several template files and each file has several available variables. They are generally used printing their values. But, if you are bit more tricky, you can also utilize their values in various different approaches.

Viewing available variables:

There is a very simple PHP function to print available variables.

Code is:

Simple use it in your template file in which you want to see variables. For an instance, I did it on node.tpl.php and I got following variables:

Output:
<?php
array(50) {
  ["template_file"]=>
  string(36) "sites/all/themes/crusti/node.tpl.php"
  ["variables"]=>
  array(48) {
    ["nid"]=>
    string(2) "16"
    ["type"]=>
    string(5) "story"
    ["language"]=>
    string(0) ""
    ["uid"]=>
    string(2) "19"
    ["status"]=>
    string(1) "1"
    ["created"]=>
    string(10) "1259101383"
    ["changed"]=>
    string(10) "1265259608"
    ["comment"]=>
    string(1) "2"
    ["promote"]=>
    string(1) "1"
    ["moderate"]=>
    string(1) "0"
    ["sticky"]=>
    string(1) "0"
    ["tnid"]=>
    string(1) "0"
    ["translate"]=>
    string(1) "0"
    ["vid"]=>
    string(2) "16"
    ["revision_uid"]=>
    string(1) "1"
    ["title"]=>
    string(18) "Example note title"
    ["body"]=>
    string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>"
    ["log"]=>
    string(0) ""
    ["revision_timestamp"]=>
    string(10) "1265259608"
    ["format"]=>
    string(1) "1"
    ["name"]=>
    string(72) "<a href="/learningd/user/19" title="View user profile.">nuchesposhes</a>"
    ["picture"]=>
    string(0) ""
    ["data"]=>
    NULL
    ["last_comment_timestamp"]=>
    string(10) "1259666378"
    ["last_comment_name"]=>
    NULL
    ["comment_count"]=>
    string(1) "0"
    ["taxonomy"]=>
    array(0) {
    }
    ["build_mode"]=>
    int(0)
    ["readmore"]=>
    bool(false)
    ["content"]=>
    string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>"
    ["links"]=>
    string(0) ""
    ["template_files"]=>
    array(1) {
      [0]=>
      string(10) "node-story"
    }
    ["node"]=>
    object(stdClass)#4 (31) {
      ["nid"]=>
      string(2) "16"
      ["type"]=>
      string(5) "story"
      ["language"]=>
      string(0) ""
      ["uid"]=>
      string(2) "19"
      ["status"]=>
      string(1) "1"
      ["created"]=>
      string(10) "1259101383"
      ["changed"]=>
      string(10) "1265259608"
      ["comment"]=>
      string(1) "2"
      ["promote"]=>
      string(1) "1"
      ["moderate"]=>
      string(1) "0"
      ["sticky"]=>
      string(1) "0"
      ["tnid"]=>
      string(1) "0"
      ["translate"]=>
      string(1) "0"
      ["vid"]=>
      string(2) "16"
      ["revision_uid"]=>
      string(1) "1"
      ["title"]=>
      string(18) "Example note title"
      ["body"]=>
      string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>"
      ["log"]=>
      string(0) ""
      ["revision_timestamp"]=>
      string(10) "1265259608"
      ["format"]=>
      string(1) "1"
      ["name"]=>
      string(12) "nuchesposhes"
      ["picture"]=>
      string(0) ""
      ["data"]=>
      NULL
      ["last_comment_timestamp"]=>
      string(10) "1259666378"
      ["last_comment_name"]=>
      NULL
      ["comment_count"]=>
      string(1) "0"
      ["taxonomy"]=>
      array(0) {
      }
      ["build_mode"]=>
      int(0)
      ["readmore"]=>
      bool(false)
      ["content"]=>
      array(5) {
        ["body"]=>
        array(5) {
          ["#weight"]=>
          int(0)
          ["#value"]=>
          string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>"
          ["#title"]=>
          NULL
          ["#description"]=>
          NULL
          ["#printed"]=>
          bool(true)
        }
        ["#title"]=>
        NULL
        ["#description"]=>
        NULL
        ["#children"]=>
        string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>"
        ["#printed"]=>
        bool(true)
      }
      ["links"]=>
      array(0) {
      }
    }
    ["teaser"]=>
    bool(false)
    ["page"]=>
    bool(true)
    ["zebra"]=>
    string(3) "odd"
    ["id"]=>
    int(1)
    ["directory"]=>
    string(23) "sites/all/themes/crusti"
    ["is_admin"]=>
    bool(true)
    ["is_front"]=>
    bool(false)
    ["logged_in"]=>
    bool(true)
    ["db_is_active"]=>
    bool(true)
    ["user"]=>
    object(stdClass)#1 (25) {
      ["uid"]=>
      string(1) "1"
      ["name"]=>
      string(8) "sakib000"
      ["pass"]=>
      string(32) "d68e84140e6956552ce2dd8edc2dd627"
      ["mail"]=>
      string(20) "sakib.live@gmail.com"
      ["mode"]=>
      string(1) "0"
      ["sort"]=>
      string(1) "0"
      ["threshold"]=>
      string(1) "0"
      ["theme"]=>
      string(0) ""
      ["signature"]=>
      string(0) ""
      ["signature_format"]=>
      string(1) "0"
      ["created"]=>
      string(10) "1255670578"
      ["access"]=>
      string(10) "1265259572"
      ["login"]=>
      string(10) "1264685758"
      ["status"]=>
      string(1) "1"
      ["timezone"]=>
      NULL
      ["language"]=>
      string(0) ""
      ["picture"]=>
      string(0) ""
      ["init"]=>
      string(20) "sakib.live@gmail.com"
      ["data"]=>
      string(6) "a:0:{}"
      ["sid"]=>
      string(26) "ucmv4i9il858vu53bh6erm2jt1"
      ["hostname"]=>
      string(9) "127.0.0.1"
      ["timestamp"]=>
      string(10) "1265259680"
      ["cache"]=>
      string(1) "0"
      ["session"]=>
      string(0) ""
      ["roles"]=>
      array(1) {
        [2]=>
        string(18) "authenticated user"
      }
    }
    ["date"]=>
    string(23) "Wed, 11/25/2009 - 03:53"
    ["node_url"]=>
    string(18) "/learningd/node/16"
    ["terms"]=>
    string(0) ""
    ["submitted"]=>
    string(112) "Submitted by <a href="/learningd/user/19" title="View user profile.">nuchesposhes</a> on Wed, 11/25/2009 - 03:53"
    ["pager"]=>
    string(0) ""
  }
  ["nid"]=>
  string(2) "16"
  ["type"]=>
  string(5) "story"
  ["language"]=>
  string(0) ""
  ["uid"]=>
  string(2) "19"
  ["status"]=>
  string(1) "1"
  ["created"]=>
  string(10) "1259101383"
  ["changed"]=>
  string(10) "1265259608"
  ["comment"]=>
  string(1) "2"
  ["promote"]=>
  string(1) "1"
  ["moderate"]=>
  string(1) "0"
  ["sticky"]=>
  string(1) "0"
  ["tnid"]=>
  string(1) "0"
  ["translate"]=>
  string(1) "0"
  ["vid"]=>
  string(2) "16"
  ["revision_uid"]=>
  string(1) "1"
  ["title"]=>
  string(18) "Example note title"
  ["body"]=>
  string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>"
  ["log"]=>
  string(0) ""
  ["revision_timestamp"]=>
  string(10) "1265259608"
  ["format"]=>
  string(1) "1"
  ["name"]=>
  string(72) "<a href="/learningd/user/19" title="View user profile.">nuchesposhes</a>"
  ["picture"]=>
  string(0) ""
  ["data"]=>
  NULL
  ["last_comment_timestamp"]=>
  string(10) "1259666378"
  ["last_comment_name"]=>
  NULL
  ["comment_count"]=>
  string(1) "0"
  ["taxonomy"]=>
  array(0) {
  }
  ["build_mode"]=>
  int(0)
  ["readmore"]=>
  bool(false)
  ["content"]=>
  string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>"
  ["links"]=>
  string(0) ""
  ["template_files"]=>
  array(1) {
    [0]=>
    string(10) "node-story"
  }
  ["node"]=>
  object(stdClass)#4 (31) {
    ["nid"]=>
    string(2) "16"
    ["type"]=>
    string(5) "story"
    ["language"]=>
    string(0) ""
    ["uid"]=>
    string(2) "19"
    ["status"]=>
    string(1) "1"
    ["created"]=>
    string(10) "1259101383"
    ["changed"]=>
    string(10) "1265259608"
    ["comment"]=>
    string(1) "2"
    ["promote"]=>
    string(1) "1"
    ["moderate"]=>
    string(1) "0"
    ["sticky"]=>
    string(1) "0"
    ["tnid"]=>
    string(1) "0"
    ["translate"]=>
    string(1) "0"
    ["vid"]=>
    string(2) "16"
    ["revision_uid"]=>
    string(1) "1"
    ["title"]=>
    string(18) "Example note title"
    ["body"]=>
    string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>"
    ["log"]=>
    string(0) ""
    ["revision_timestamp"]=>
    string(10) "1265259608"
    ["format"]=>
    string(1) "1"
    ["name"]=>
    string(12) "nuchesposhes"
    ["picture"]=>
    string(0) ""
    ["data"]=>
    NULL
    ["last_comment_timestamp"]=>
    string(10) "1259666378"
    ["last_comment_name"]=>
    NULL
    ["comment_count"]=>
    string(1) "0"
    ["taxonomy"]=>
    array(0) {
    }
    ["build_mode"]=>
    int(0)
    ["readmore"]=>
    bool(false)
    ["content"]=>
    array(5) {
      ["body"]=>
      array(5) {
        ["#weight"]=>
        int(0)
        ["#value"]=>
        string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>"
        ["#title"]=>
        NULL
        ["#description"]=>
        NULL
        ["#printed"]=>
        bool(true)
      }
      ["#title"]=>
      NULL
      ["#description"]=>
      NULL
      ["#children"]=>
      string(296) "<p>node (story) - Eros turpis probo distineo pala pala molior comis utinam. Jugis damnum augue lucidus nulla ymo modo lucidus secundum. Diam macto euismod gravis ea. Blandit quae blandit. Dignissim bene comis eligo hos sino. Usitas jumentum volutpat enim dolor quae vindico aptent roto cogo.</p>
"
      ["#printed"]=>
      bool(true)
    }
    ["links"]=>
    array(0) {
    }
  }
  ["teaser"]=>
  bool(false)
  ["page"]=>
  bool(true)
  ["zebra"]=>
  string(3) "odd"
  ["id"]=>
  int(1)
  ["directory"]=>
  string(23) "sites/all/themes/crusti"
  ["is_admin"]=>
  bool(true)
  ["is_front"]=>
  bool(false)
  ["logged_in"]=>
  bool(true)
  ["db_is_active"]=>
  bool(true)
  ["user"]=>
  object(stdClass)#1 (25) {
    ["uid"]=>
    string(1) "1"
    ["name"]=>
    string(8) "sakib000"
    ["pass"]=>
    string(32) "d68e84140e6956552ce2dd8edc2dd627"
    ["mail"]=>
    string(20) "sakib.live@gmail.com"
    ["mode"]=>
    string(1) "0"
    ["sort"]=>
    string(1) "0"
    ["threshold"]=>
    string(1) "0"
    ["theme"]=>
    string(0) ""
    ["signature"]=>
    string(0) ""
    ["signature_format"]=>
    string(1) "0"
    ["created"]=>
    string(10) "1255670578"
    ["access"]=>
    string(10) "1265259572"
    ["login"]=>
    string(10) "1264685758"
    ["status"]=>
    string(1) "1"
    ["timezone"]=>
    NULL
    ["language"]=>
    string(0) ""
    ["picture"]=>
    string(0) ""
    ["init"]=>
    string(20) "sakib.live@gmail.com"
    ["data"]=>
    string(6) "a:0:{}"
    ["sid"]=>
    string(26) "ucmv4i9il858vu53bh6erm2jt1"
    ["hostname"]=>
    string(9) "127.0.0.1"
    ["timestamp"]=>
    string(10) "1265259680"
    ["cache"]=>
    string(1) "0"
    ["session"]=>
    string(0) ""
    ["roles"]=>
    array(1) {
      [2]=>
      string(18) "authenticated user"
    }
  }
  ["date"]=>
  string(23) "Wed, 11/25/2009 - 03:53"
  ["node_url"]=>
  string(18) "/learningd/node/16"
  ["terms"]=>
  string(0) ""
  ["submitted"]=>
  string(112) "Submitted by <a href="/learningd/user/19" title="View user profile.">nuchesposhes</a> on Wed, 11/25/2009 - 03:53"
  ["pager"]=>
  string(0) ""
}
 
?>

For example, you can determine the current comment status of a node by viewing $comment variable.

<?php
$comment = 0; // Comment is disabled
 
$comment = 1; // Comment is Read only
 
$comment = 2; // Comment is set to Read/Write
?>
Now you can imagine how useful these variables are even if you do not print them directly your page.
Posted under:

Comments on this post

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
3 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Custom Services

If you are looking a Drupal theme or project developer, feel free to contact me.

Contact

Recent Free Themes

Recent Articles


Browse