The difference between $page and $teaser for node theming

I have always been a bit confused by this one. Why does theme_node have both $page and $teaser as parameters ? Surely, if it's not a page then it is a teaser ? Not quite.


function theme_node($node, $teaser = 0, $page = 0) {
.....

The docs don't quite spell it out clearly, but once you know the difference, you can see what they are saying. However, if you have not quite understood the difference, the docs don't help one bit. Here is my attempt to clarify.

$teaser - the easy one
When you are displaying the teaser view of a node, then $teaser will be true, and, in every situation I have come across, $page will be false. This is simple, you know that you are rendering a node teaser, just go ahead and do your thing.

$page - a little more complex
When $page is true, you are on a node page ( arg(0) == 'node' ). In this case, like the docs say, we don't generally display th node title because that will be rendered by the page template.

When $page and $teaser is false
This is the special one. If you use views, you may hit this rather often. This scenario will occur when you are rendering a view with a set of full nodes. So, you are not on a node page ( arg(0) != 'node' ) and you are not displaying teasers.

So, there is nothing too complex, and once you know the difference, it's worth the occasional pause to think which variables to check, but, most of the time, it;s easy.

Subjects:


Add the first review

Write a review

Don't be shy, say hello. We'd love to hear from you.


[email protected]