How do i use a template file to display content

W0lvEriNE - November 12, 2007 - 10:13
Project:RelatedContent
Version:5.x-1.6
Component:Code
Category:support request
Priority:normal
Assigned:TBarregren
Status:closed
Description

I am trying to use a node.tpl.php file to display the content in my simplenews newsletter. I am using RelatedContent to add content into my newsletter (using a view i called Newsletter) - what must i call the tpl file so that i can stop it showing terms, comments etc on the newsletter display?

Many thanks in advance

#1

Michelle - February 2, 2008 - 04:15

After much frustration, I figured out how to do this. It requires a tiny hack to the module, though. Would be lovely if it could get committed.

In relatedcontent.module, line 1182, put:

        $n->relatedcontent = TRUE;

So it looks like:

<?php
     
if ($nid && ($n = node_load($nid)) && node_access ('view', $n)) {
       
$n->relatedcontent = TRUE;
       
$args[0] = $n;
?>

Then in _phptemlate_variables of template.php for the 'node' hook, put:

<?php
   
if ($vars['node']->relatedcontent == TRUE) {
     
$vars['template_file'] = "newsletter-teaser";
    }
?>

In your theme directory, create a file called node-teaser.tpl.php and put this in it:

<?php
print l($node->title, "node/$node->nid");
print
$node->teaser;
?>

That will make it just print the linked title and teaser part when the node is displayed as related content. If you want to use related content for other things than the newsletter, you'll need to put more conditions in, but this did enough for my purposes. :)

Michelle

#2

TBarregren - February 2, 2008 - 09:56
Version:5.x-1.1» 5.x-1.6

Michelle,

Looking at your code, it seems to me that you meant to post this comment to the issue #215123. :-) Could you please re-post it there.

BTW, I am planing to incorporate the title-only feature in next version of RelatedContent. Your hack seems to be a reasonable way to go. I would however do a minor change: Instead of setting $n->relatedcontent = TRUE, I would set $n->relatedcontent = $node->nid. This can be used in node.tpl.php, for an example, to adapt the theming of the embedded node with the related content. It can also be used to provide a solution to the feature request in #211871.

#3

TBarregren - February 2, 2008 - 10:05
Assigned to:Anonymous» TBarregren
Status:active» fixed

W0lvEriNE,

Since the teasers are themed by the regular node theming mechanism, it means you have all those possibilities. You could for an example use a special content type for your related content, and then create a specific template file for that content type. You could also use Michelle's approach, or the variant of mine, to get knowledge of the context within the template. Finally, I think you also can use Node Info module.

#4

Michelle - February 2, 2008 - 14:49

TBarregren - I don't understand... That issue you pointed to is about making a titles only listing, which isn't what I wanted to do. I was looking for a way to theme the teasers with a .tpl specific to when the teaser is in a RC listing, which is exactly what the OP of this issue wanted to do. So it seems much more relevant to this issue than the other one. Your point of setting it to the nid of the parent node is a good one, though. If you could add that line into the module, that would be great. I hate having a hacked module on a client site because you just know that somewhere along the line it's going to get updated and lose the line and then the newsletters will stop working properly.

Thanks,

Michelle

#5

TBarregren - February 2, 2008 - 17:35

You are of course right, #215123 isn't the right place for your feature request. But I still think it would be a good thing to move this discussion to another issue, preferably an own, since your feature request is very good, and I would like to keep it open while still closing this support request.

#6

Michelle - February 2, 2008 - 18:59

Done :)

Michelle

#7

TBarregren - February 2, 2008 - 22:55

Thank you Michelle.

#8

Anonymous (not verified) - February 16, 2008 - 23:01
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.