Absolute URL paths

Just stumbled onto this nice little function, probably not big news to Drupal code-heads... but as a themer that frequently works in a staging development environment, I find that sometimes I'll need to use an absolute path for an image path or whatever.

Well, if you need to print the absolute path to a given file, use the url() function:

http://api.drupal.org/api/function/url/6

The fourth argument of the function allows you to make it return the absolute path, including the http:// and the domain part.

Usage:

<?php print url($node->nid, NULL, NULL, TRUE) ?>

The TRUE switch will make it print something in the form of: http://www.yourdomain.com/node/16