I'm a graphic designer, and I've been working at learning Drupal theming for the past few years now. I'm no PHP expert, but I've spent quite a while teaching myself PHP and PHPTemplate. Despite this, I still have yet to understand the rhyme or reason behind the $content call in a PHPTemplate theme. I feel like I'm missing something very fundamental. Am I?
This $content call seems, to me, to be something of a magical pill, which you can just plop into a .tpl.php and have it output... well... stuff. Sometimes it's handy, but sometimes it's downright annoying because it undoes any fine-grain modification of how a node appears by just dumping out the entire node the default way Drupal does it. I suppose this could be why Drupal sites all look the same?
Why, for example, does $content always output both the copy (as in the text) of the page, AND the comments attached to it? Should I not be able to decide where in the node I wish to place comments? What if I want them in another column? As far as I can tell, there's no equivalent $comments that only outputs the comments of the current node.
Or (for another example) why does creating a node-image.tpl.php and then placing the $picture call before the $content call result in... well... nothing. My image thumbnails still display below the node's text, and I suspect that's thanks to $content's catch-all output. What am I missing here? It's frustrating, and using Drupal it takes far longer to design a site template for a client that meets the exact visual specifications we (designers) develop than it does to just have someone code the site from scratch.
I read a lot about how people would like designers to start making more and more cool/innovative/clever themes to 'compete' with Wordpress, etc., but every time I try to code a theme that doesn't look so obviously Drupal, I continue to run into roadblocks like these.
I suppose all I'm really trying to ask is: is it possible to code a PHPTemplate without once falling back on the catch-all $content?
Comments
One thought
I can appreciate your post - $content is great when you don't need granularity. It rolls up a whole lotta variables, making theme templates much cleaner and easier about 70% of the time. For the other times - you need to know what is available to call directly. So stick a
print_r($node);in the node or page templates. You'll get a dump of the $node object - and can then do things like if you just want the body copy,print $node->bodyor if you just wanted the created date...print $node->createdcan really get very very specific with how things are being output in your theme.Good luck,
-G
Contemplate is your answer
The contemplate module will, for any given node type, show you exactly what's going on in $content, and will allow you to choose exactly how to output it.
One thing missed in the other two posts
$content has context in page.tpl.php besides being a single node it is the main part of any page, be it a list of nodes, a set of panels, an edit page and admin page, etc.
Within node.tpl.php it is the format version of the nodes content. $node holds the raw data. $picture is not part of the node put the picture (if they have one) of the user who created the node.
If you visit http://drupal.org/phptemplate it talks about the various tpl.php files and the variables that are available with each template