After diving to the world of Drupal and following Lullabot's excellent "How To Build Flickr In Drupal" (I'm still having trouble getting the views to work correctly though) I am now altering the custom node-image.tpl.php file. My only stumbling block is not knowing the full list of variables that are avaliable to me. Can anyone help?

I simply want to print the code for a thumbnail image, but echo $content gives me the photos AND textual content. Can I print just the image?

And is there any method to print all avaliable variables, or even some documentation listing the variables I have access to?

Thanks in advance.

Comments

Some suggestions

Did you take a look at the following book page :

http://drupal.org/node/11816

It gives the list of available variables in template.

If it doesn't help and you don't find any other solution, you can do it the "brute" way :

<?php
...
// Code not tested, but it gives the idea
$tag_start=strpos($content,'<img ');
$tag_end=strpos($content,'>',$tag_start);
$image=substr($content,$tag_start,$tag_end-$tag_start+1);

// Do what you want with $image
...
?>

Thank You

Thank you! This is just the type of thing I was looking for.

While I can see the advantages of pre-compiling certain parts of the template - so that echo $picture; will quickly and easily print <div class="picture"><a href="/user/1" title="View user profile."><img src="http://www.mydomain/files/pictures/picture-1.jpg" alt="User&#039;s picture" title="User&#039;s picture"  /></a></div>, it would seem strange that I cannot have more control over the code without resorting to string manipulation.

A Solution?

I have just stumbled across the Contemplate module - http://drupal.org/project/contemplate - which sounds like it will allow me more control over the final output of my code, but it still seems strange to need an additional module to access node variables. Oh well.

Accessing node variables

You can do this with something like : $node=node_load($nid);.

$node=node_prepare($node); will allow you to generate the filtered content.

Thanks

Thanks for that. I shall look them up in the API and try them out.

Variables

After experimenting, I have discovered that I can access node variables in the following way...

echo "<p>nid: ".$node->nid."</p>";
echo "<p>vid: ".$node->vid."</p>";
echo "<p>type: ".$node->type."</p>";
echo "<p>status: ".$node->status."</p>";
echo "<p>created: ".$node->created."</p>";
echo "<p>changed: ".$node->changed."</p>";
echo "<p>comment: ".$node->comment."</p>";
echo "<p>promote: ".$node->promote."</p>";
echo "<p>sticky: ".$node->sticky."</p>";
echo "<p>revision_timestamp: ".$node->revision_timestamp."</p>";
echo "<p>title: ".$node->title."</p>";
echo "<p>body: ".$node->body."</p>";
echo "<p>log: ".$node->log."</p>";
echo "<p>format: ".$node->format."</p>";
echo "<p>uid: ".$node->uid."</p>";
echo "<p>name: ".$node->name."</p>";
echo "<p>picture: ".$node->picture."</p>";
echo "<p>data: ".$node->data."</p>";

echo "<ul>";
foreach ($node->images as $key=>$value) {
echo "<li>".$key.": ".$value."</li>";
}
echo "</ul>";

echo "<p>last comment timestamp: ".$last_comment_timestamp."</p>";
echo "<p>last comment name: ".$last_comment_name."</p>";
echo "<p>comment count: ".$comment_count."</p>";

echo "<ul>";
foreach ($node->taxonomy as $item) {
echo "<li><ul>";
echo "<li>tid: ".$item->tid."</li>";
echo "<li>vid: ".$item->vid."</li>";
echo "<li>name: ".$item->name."</li>";
echo "<li>description: ".$item->description."</li>";
echo "<li>weight: ".$item->weight."</li>";
echo "</ul></li>";
}
echo "</ul>";

echo "<p>readmore: ".$node->readmore."</p>";

echo "<ul>";
foreach ($node->files as $item) {
echo "<li><ul>";
echo "<li>fid: ".$item->fid."</li>";
echo "<li>nid: ".$item->nid."</li>";
echo "<li>filename: ".$item->filename."</li>";
echo "<li>filepath: ".$item->filepath."</li>";
echo "<li>filemime: ".$item->filemime."</li>";
echo "<li>filesize: ".$item->filesize."</li>";
echo "<li>vid: ".$item->vid."</li>";
echo "<li>description: ".$item->description."</li>";
echo "<li>list: ".$item->list."</li>";
echo "</ul></li>";
}
echo "</ul>";

echo "<ul>";
foreach ($node->links as $item) {
echo "<li>".$item."</li>";
}
echo "</ul>";

subscribing

subscribing

http://SocialNicheGuru.com
Creating gurus to deliver the right product and the right message to the right niche at the right time

or

<?php
 
print '<pre>';
 
print_r ($node);
  print
'</pre>';
?>

What about human readable version of node type?

I know you can easily use $node->type variable but this is the machine version. I'd like to print the human readable version of node-type wich sometimes contains caps, spaces and other symbols. Any idea or suggestion?

...help Drupal grow, whatever you do matters.

nobody click here