How to access Drupal variables in a PHP included file? I have a snippet of HTML that I've saved in my theme as mysnippet.inc. I'm using this code in template files (eg. node.tpl.php) to include it:

&lt;?php include($directory."/includes/mysnippet.inc"); ?&gt;


This is working fine, but the snippet also needs to access Drupal variable $node_url. So I tried to global it into my snippet:

&lt;?php global $node_url ; ?&gt;
&lt;?php print $node_url; ?&gt;


This doesn't work. 

What would be the best way to achieve this? Should I be using template.php to create a variable containing my code snippet instead?
You can access the $variables array in your included file like this:

 // assuming you are viewing a node
 $node = $variables['node'];
 // the node is an object, so to display the url do
 echo drupal_get_path_alias('node/'.$node-&gt;nid);


To see what kind of data the $variables array contains do something like:

 echo '&lt;pre&gt;';
 print_r($variables);
 echo '&lt;/pre&gt;';