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

TBarregren’s picture

Assigned: Unassigned » TBarregren

I will include this in next version of RelatedContent.

TheoRichel’s picture

Michelle, 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:

function  _phptemplate_variables($hook, $vars) {
   switch($hook) {
     case 'comment' :
        $vars['newvar'] = 'new variable';
        $vars['title'] = 'new title';
        break;
   }
   return $vars;
}

Then I am confused where to merge this with your code. Can you please help?

Many thanks,

Theo Richel

Michelle’s picture

I've got an explanation of that function in my advprofile docs here: http://drupal.org/node/207841

Michelle

TheoRichel’s picture

Michelle, 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

Michelle’s picture

Hmm... 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

TheoRichel’s picture

Yes!
That did it. Many thanks. I suppose I can take it from here.
BTW, where IS the Couleeregion

Thx

TR

Michelle’s picture

It's the area around La Crosse, Wisconsin.

Glad you got it working. :)

Michelle

TheoRichel’s picture

Well 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

TBarregren’s picture

The 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.

TheoRichel’s picture

OK, done, thank you.

TR

TBarregren’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

TBarregren’s picture

Status: Closed (fixed) » Fixed

I 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.)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

TBarregren’s picture

Version 1.7 of RelatedContent includes this feature request.

fictionindustries’s picture

is this included in the 6 version?
If yes, how does it work?

peter-boeren’s picture

Version: 5.x-1.x-dev » 6.x-1.0
Status: Closed (fixed) » Active

This issue has not yet found its way into D6. I will take a look at the changes made by Thomas in version 1.7.

peter-boeren’s picture

Assigned: TBarregren » peter-boeren