This is a spin-off of http://drupal.org/user/23570
There is currently no way to use a .tpl file to theme nodes only when they are being shown as related content. To do this, we need to be able to identify from _phptemplate_variables that this node is part of the r.c.
To do this needs a line added to the relatedcontent.module at line 1182:
$n->relatedcontent = $node->nid;
So it looks like:
if ($nid && ($n = node_load($nid)) && node_access ('view', $n)) {
$n->relatedcontent = $node->nid;
$args[0] = $n;
You use this in the "node" hook of _phptemlate_variables in template.php. Here is an example:
if (is_set($vars['node']->relatedcontent)) {
$vars['template_file'] = "newsletter-teaser";
}
This says to use the template file newsletter-teaser.tpl.php for the node only when the node is being viewed as related content. This allows you to have teasers for the nodes themed differently when shown in other parts of the site. Because you have the NID of the parent node, you can get fancier, but this is a simple example.
To show just the title and the teaser without the tags, author, etc, create a file called newsletter-teaser.tpl.php in your theme directory, and put this in it:
print l($node->title, "node/$node->nid");
print $node->teaser;
Michelle
Comments
Comment #1
TBarregren CreditAttribution: TBarregren commentedI will include this in next version of RelatedContent.
Comment #2
TheoRichel CreditAttribution: TheoRichel commentedMichelle, I do not understand, my PHPTemplate (Channel9) does not contain a line with _phptemplate_variables.
If I just copy your lines to that file I get errors, I
f I copy this from the Drupal-site:
Then I am confused where to merge this with your code. Can you please help?
Many thanks,
Theo Richel
Comment #3
MichelleI've got an explanation of that function in my advprofile docs here: http://drupal.org/node/207841
Michelle
Comment #4
TheoRichel CreditAttribution: TheoRichel commentedMichelle, thank you very much! Your explanation is very clear. However I still get this error message:
Fatal error: Call to undefined function is_set() in /home/www/klimatosoof/sites/default/themes/themagrk/template.php on line 76
This is the code I made, based on your suggestions:
function _phptemplate_variables($hook, $vars) {
if (is_set($vars['node']->relatedcontent)) {
$vars['template_file'] = "newsletter-teaser";
}
return $vars;
}
Many thanks again
Comment #5
MichelleHmm... Wierd. That's a PHP function. Try just
if ($vars['node']->relatedcontent) {
. That should just return true if $node->relatedcontent is non 0 but I'm not sure how it will react if the var doesn't exist and I'm not in a position to test right now.Michelle
Comment #6
TheoRichel CreditAttribution: TheoRichel commentedYes!
That did it. Many thanks. I suppose I can take it from here.
BTW, where IS the Couleeregion
Thx
TR
Comment #7
MichelleIt's the area around La Crosse, Wisconsin.
Glad you got it working. :)
Michelle
Comment #8
TheoRichel CreditAttribution: TheoRichel commentedWell almost, allow me one more question. I have been struggling all day with it. Here: http://www.groenerekenkamer.nl/node/164 is my crude version of a newsletter. At a height of about 10 cm you see the word 'story', now how do I get rid of that?
Many thanks,
Theo Richel
Comment #9
TBarregren CreditAttribution: TBarregren commentedThe heading 'Story' is the title of the output group. You can either remove it from the template, or turn grouping off at
admin/content/types/newsletter
.Comment #10
TheoRichel CreditAttribution: TheoRichel commentedOK, done, thank you.
TR
Comment #11
TBarregren CreditAttribution: TBarregren commentedComment #12
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #13
TBarregren CreditAttribution: TBarregren commentedI have added Michelle's suggested change to the head of the DRUPAL-5 branch. Thus the upcoming nightly development snapshot, 5.x-1.x-dev, will include it.
(I noticed that I already once have checked this issue fixed. That was obviously a mistake. I am sorry.)
Comment #14
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #15
TBarregren CreditAttribution: TBarregren commentedVersion 1.7 of RelatedContent includes this feature request.
Comment #16
fictionindustries CreditAttribution: fictionindustries commentedis this included in the 6 version?
If yes, how does it work?
Comment #17
peter-boeren CreditAttribution: peter-boeren commentedThis issue has not yet found its way into D6. I will take a look at the changes made by Thomas in version 1.7.
Comment #18
peter-boeren CreditAttribution: peter-boeren commented