Finding that Drupal Varible

Customising a content type?

Cant find that elusive variable for something? Well this is what you do.

I remember when I first started working with Drupal, one of the biggest challenges when theming was discovering what variables were available to me.
Eventually I found out - Heres how to do it. Put this code inside a blahhhblah.tpl.php file and it will display all the variables available to use.

print "<pre>";
print_r(get_defined_vars());
print "</pre>";

 

 OR

get_defined_vars();

This will give you a list like this one: (this is generated from inside comment.tpl therefore it contains the comment variables only. )

stdClass Object ( [author] => Josh Weaver [subject] => TEST [comment] =>TEST
[format] => 1
[cid] =>
[pid] =>
[nid] => 86
[uid] => 1
[submit] => Save
[op] => Preview
[preview] => Preview
[form_build_id] => form-d0d24ef2b32ec2442f039de8ad26bb74
[form_token] => 4acb2a9f4a8b0ba23aa27345020722be
[form_id] => comment_form [date] => now
[timestamp] => 1279484164 [name] => Josh Weaver
[new] => 2 [signature] => )
 

Now lets say we want to print the commenter name without any link - check_plain($comment->name);

That will do it, without the check_plain();
It will usually be in a link format linking to there profile by default.

 If your stuck on this comment and ill get back to you with a solution. & ill update this page.