Hi There -
Have a content type whose teaser needs to be displayed differently whether it's on a page or whether the teaser's in one of two different blocks. (Needs to be displayed differently in each block and differently again in a view on a page.)
One of the blocks is a node queue and the other is a view.
Unfortunately, the variables available in $block, like $block->module or $block->delta are unavailable to the teaser template, only the block template.
I need to have a conditional in the teaser template to display a teaser one way or another depending on the context. I've been successful in using the
<?php
if ($teaser) {
} else {
?>
construct, but the teaser template does not see any of the $block variables.
Have tried putting variables into the header of the block in both view and block, and they remain unavailable as well.
How do I get a contextual variable to my teaser template?
There is a dent in my desk where my head has beaten it in. Please help.
Comments
For the question of views I
For the question of views I use the approach outlined at http://drupal.org/node/299660#comment-978739. As for node queue I wonder if they have a similar theme function.
Nevets! Once again, thank you.
That's a very very cool approach and gets me halfway there. Now I need to distinguish between whether the teaser is in a page or a block for the same view. The teasers need to be different depending on whether the $content is in a page or a block and then there's the nodequeue thing.
But before I move on, I'd like to linger on what you wrote in the other post. How did you come up with that function? Where do you find out that $view is available to template.php? When you're looking into a module, how can you tell what's going to be available to the block template or the page template or the node template. If you're writing a module, how to you tell a variable where its new home will be?
If I'm only using teasers, would I make $teasers = true? I went and looked up node_view and I wasn't able to discern. It seemed that even though $teasers = false, it would still output teasers.
Am I correct in understanding that the function isn't part of the big grandaddy switch statement under case 'node'?
BTW Congratulations on the book! I'll be first in line at Amazon to pre-order, and I'm sure I won't be alone. You've helped so many people and know Drupal so well. Can't wait!
The function comes from
The function comes from reading http://drupal.org/node/42597. The value passed as $teaser to node_view determines the value passed to node.tpl.php (and it's variations). For CCK types it is also used to determine how fields are displayed. Custom content types may do the same in their view function. If the content type uses 'body' for teasers it may be truncated (depends on site settings). Note that $view is not available to template.php, its available to the theme function that is be overridden. As for block vs page the view contains a field that tells you this, you can temporarily add
<pre><?php print print_r($node->view, TRUE); ?></pre>at the end of node.tpl.php to see the fields for the view (one of them will reflect if it is a page or block view).Note sure what you are referring to with "Am I correct in understanding that the function isn't part of the big grandaddy switch statement under case 'node'?"
As for the book I am not sure what you are talking about since I have not written one (thanks anyway).
Yep, he was right. You're a bloody genius.
Can see all of the important info in the node object now and I think I can get the rest going. I'll be able to spend more time tomorrow at the theming views page you pointed me to. I am incredibly grateful. Thank you.
RE the book: nine times out of ten, when I find the answer to something I'm looking for in the forums, you've provided it - patiently, accurately, thoroughly and concisely. When I heard you were coming out with a book, I was completely delighted - there's no one better to write it.
You have huge cred within the community and I'd feel very comfortable handing something you wrote to anyone who wanted to learn Drupal - no matter what their skill level. I don't think I'd say that for anyone else's book. With the growing interest in Drupal from the outside world, would you consider writing a book? You could go through your posts and see what you've answered and group them. Rewrite the text some and generalize the code and that could be the bulk of the book. You could pair up with someone else to work on the rewrites so that your main work would be editing. Your posts would be a great gauge of what people really need to understand - just because you've answered so many of them with such clarity. You'll also be able to anticipate the issues that the genpop will have with upcoming versions because you've spent so much time answering so many of our questions.
I don't think it would be hard for you to get a book deal. Publishers are looking for Drupal books.
You're an excellent teacher. No one is better qualified to create a document for learning Drupal. It would also be a way for those of us whom you've helped to give back to you by purchasing it. While I know your spending so much time helping people on the forums is a wonderful act of giving, letting us have an opportunity to give back to you would also be nice. Karmic balance would be good for us too. Please at least think about it. I know I'm not the only person who thinks you're awesome.
Thank you much for the
Thank you much for the compliments.