I am working on my own gamereview module. I would like to override the default teasers that show up on the front page so as to show the publisher, developer, rating, etc. from my gamereview database, and also to give them their own css (right now the teasers all show up as 'div class="node"' but I'd like them to be something like 'div class="gamereview"'. Basically I want complete control over how the teasers are displayed, including the title. I can see that there is a $teaser variable passed into hook_view() but I don't know if it does the right thing or what to do with it.

Comments

madivad’s picture

Doesnt allow you to do all the things you want, but it does allow for a seperate teaser. Maybe experiment and see what you can do with that

nevets’s picture

If you are using phptemplates check out http://drupal.org/node/17565. If this is a custom module copy node.tpl.php to node-gamereview.tpl.php (assuming your module is called gamereview) and then edit node-gamereview.tpl.php.

(If you are using flexinode as a base, there is a link to theme flexinode content also).

SorcererXIII’s picture

Ah, I didn't realize that node-gamereview.tpl.php would be used for the teaser listings in addition to the full pages! That seems like a weird way of doing things . . . anyway, now all I need to do is figure how how to test if I'm in "teaser display" mode or not within that page, and I can output a different css class.

I guess I can parse the URI to find out if I'm on the front page or not but that seems a little roundabout . . . anyone know a better way?

nevets’s picture

There is documention on node.tpl.php that talks about the variables that are available globally. These include $page (if set, content is being displayed by it's self on a page) and $teaser (which should be set when the template is rendering a teaser).

SorcererXIII’s picture

Sorry, as unbelievable as it sounds I somehow missed that page of the documentation. But now I've got code in my gamereview.tpl.php that tests the $page variable and does just what I want . . . thanks all!

nedjo’s picture

Theme-level work is great, but won't work for others using your module unless they use the same theme.

hook_view() allows you good control over display. You can simply reset $node->teaser before it's passed to the theme. E.g.,


function gamereview_view(&$node, ...) {
  ...
  $node->teaser = theme('gamereview_teaser', $node);
  ...
}

function theme_gamereview_teaser($node) {
  $output = '<div class="whatever">';
  $output .= $node->whatever_field;
  $output .= '</div>';
  ...
  return $output;
}
SorcererXIII’s picture

Thanks, nedjo. Your example made more sense to me than the drupal's own docs did. Now I can change the text that is displayed in the teaser . . . however, but I also want to change the whole look of the header, etc - I sort of want the whole teaser, with its title, to be one unit, with different formatting from non-gamereview teasers (so that readers can easily spot a gamereview as opposed to a blog entry). I can't think of how to do this without depending on phptemplate and node-gamereview.tpl.php.

It strikes me as strange that it is the same code that governs both the teaser and the full node display, the only difference being the $teaser variable set to true . . . seems not as object-oriented as the rest of drupal.

With regards to theme compatability . . . my gamereview module is probably a little too specialized already to be useful to the general drupal user - they would be better off modifying bookreview, I think, which is how I started. But ultimately I think someone should come up with a more general "review" module that lets you specify your own fields for the type of review you want and stores different review types in a table . . . I almost did just that but realized I don't have the free time to write such a beast. But I intend to post the gamereview.module and related code once my page is up and going.

madivad’s picture

What you could also do is (if you're going to use your own node-gamereview.tpl.php) change the relevant classes to your own classes and add them to your css.

If you check out the original node.tpl.php you'll see the obvious places you need to change, in fact your could even get away with as little a change such as (from line 1)
<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">

to something like:
<div class="gamereview<?php print ($sticky) ? " sticky" : ""; ?>">

By keeping the sticky and setting two classes in your css, you can have sticky reviews if you'd like, although that would probably be overkill

Hope this helps.

SorcererXIII’s picture

I also added a test in there to print the class "gameteaser" if it's a teaser and "gamereview" if it's a $page. The rest is taken care of by the css. And it is working! Thanks!

sangamreddi’s picture

atin81’s picture

Are you still development this module???????