Quick question ...

I've stumbled across variables here and there that let you put Drupal variables in content. For example, you can include the current user's username in a page to make it appear personalized.

I've searched around, but probably because I do not know the exact term for what I seek, I've been unable to find a list of these variables anywhere.

I'm sure this is readily available ... somewhere. Anyone know?

Brian

Comments

NancyDru’s picture

catch’s picture

I don't know of a single list anywhere. Somewhere to start looking is api.drupal.org - although you sort of need to know what you're looking for in the first place for that.

bchoc’s picture

Knowing, for example, how to display the logged in username has not helped me figure out how to display the node author's username, if it's possible. I could ask each time, I suppose.

NancyDru’s picture

There is no law against reading the core module code or the theme's code. Those things might be there and readily available. At the least, you'll probably find some query snippets you could lift.

Nancy W.
now running 5 sites on Drupal so far
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in Your Database

NancyDru’s picture

If the node is already loaded, it has a "uid" field in the node's object. That can be used to get the information for the user, such as the username, by doing a user_load function.

If the node isn't fetched yet, you can do a JOIN on the user table to get the user's name.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

EWoods’s picture

I realize this topic is old, but it came up for a search I did on "Drupal variables" and I think my own findings may be of interest to some:

So, hopefully that'll be of use to others searching for similar and not getting there directly.

mlle.yotnottin’s picture

The variables that are available at any given time depend on where in the program you are. It can all be rather confusing at times.

However, in my search for the same information I've found a couple of resources that have proven useful:

This one usually provides very useful information when inserted somewhere in the code:

print "<pre>";
print_r(  $name_of_object  );
print "</pre>";

Use var_dump instead of print_r: http://drupal.org/node/58723

PHP Debugger (old but maybe useful): http://drupal.org/node/1466

And of course the devel module

It would be nice if there were a complete variable list available but considering the dynamic nature of Drupal and Php and the scope within which one is working at any given time, I'm not sure we'll ever see anything that is both useful and relevant..

karol.haltenberger.old’s picture

get_defined_vars() should give you an array of variables defined in the current context

Jey.keu’s picture

Thanks LoRaK...ur reply was helpful...

Live long.

davidshaw’s picture

As of writing only Drupal 6 and 7 are listed but its a start :)

http://api.drupal.org/api/globals

loopduplicate’s picture

first off, copy the globals.php file into a new folder in your Drupal install called developer. ie: mysitename/developer/globals.php

then get netbeans, which code suggests for you all the variables because it analyzes your whole site to see what global variables there are.

get netbeans, it's free, open up page.tpl.php or whatever template you are working on, then type in <?php $ and it will list all your choices.

charlie-s’s picture

Think of it this way.

Every variable that has been entered into your database is available to you.

What are you looking to print to the screen?