I'm currently developing (theming) my first drupal site and though I'm not really sure I need this, I was wondering if it was possible to theme a node differently depending on the page it shows on? For example, I'd want all my story node teasers to be themed in a particular way when displayed on the front page, but when they're displayed in the Stories page, I'd want them to be themed differently.
I know that creating node-story.tpl.php controls the display of all my story nodes so would it be as simple as inserting a variable in my theme _phptemplate_variables and controling the display of the node right into node-story.tpl.php depending on the value of that variable? If so, how can I know the destination page where the node will be rendered?
Thanks for your help and sorry if that question was already asked somewhere else, I couldn't find anything like it. I still see a little magic going on but everyday I figure out some of the tricks and makes my drupal developement more enjoyable.
-francis
PS: Is there a doc or something available to know what are all the possible $hook and $vars _phptemplate_variables can receive?
PPS: Is there a way to debug and step into php code for debugging and learning purpose?
Comments
Couple Things
debugging... check out phpeclipse and the devel module.
The hooks that _phptemplate_variables can call are tied to the theme function being executed. Sadly, I don't know of any documentation on this. But, I can tell you some of them are node, block, and page.
$vars can be anything you want. If it exists the old value will be overridden and if it's new you have a new variable.
Now, if you want to know if a node is on the front page here is a little trick to help. Let's create a variable called $is_front that's available in your node.tpl.php files. This variable is available in the page.tpl.php files already. It will be true if it's the front page and false if it isn't.
This help?
--
Matt
http://www.mattfarina.com
Extending this a bit
I found this because I was looking for what the original poster wanted to do (i.e. display nodes differently for the front page).
In addition to adding
to template.tpl.php (thus making $is_front available to node.tpl.php), first I copied node.tpl.php file to create node-front.tpl.php.
Then I added
to the very beginning of node.tpl.php.
Of course there is no explicit reason to put the modified node in its own file as opposed to putting an if...elseif...endif construct but I like it for neatness' sake.
I tried making node-front.tpl.php without adding the include but it seems that PHPTemplate doesn't pick up that template file for nodes like it picks up template files for different pages, blocks, etc. I was hoping it would look for "node-pagename.tpl.php."
You can theme a specific node, however, which I didn't know before this exercise:
http://drupal.org/node/136647
As for debugging, these instructions worked for me:
http://drupal.org/node/157609
I'm also running MAMP (the LAMP stack on OS X) for local debugging.
Andre'
For another option that
For another option that relies more heavily on CSS, you can add a class to your body tag based on just about any variable available to you in Drupal. This is useful if your markup is identical or nearly identical for some of your pages and just making some style changes is needed.
For example, if I want to style something differently based on content type, I'd put the following for the opening body tag in my page.tpl.php file: