Hello!!

I´m sorry by my bad inglish :(.

I try show result search as teaser that I create with module contemplate but show me the teaser as if I`m not create the teaser with contemplate.

In file template.php in folder thems/darkgreen I write:

function darkgreen_search_item($item, $type) {
  $output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']).'</a></dt>';

  $node=$item['node'];
  $output .= $node->teaser;
  
  return $output;
}

When I search the teaser show me not is the teaser that I define in teaser of contemplate else the teaser as if I have not define the teaser of contemplate.

Thank you.
Again I´m sorry my bad inglish.

Comments

jrglasgow’s picture

Contemplate doesn't actually change the teaser in the database, it uses the hook_nodeapi() to adjust the teaser.

function darkgreen_search_item($item, $type) {
  $output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']).'</a></dt>';

  $node=$item['node'];
  //we tell it to run contemplate_nodeapi() telling it we are going to view the node and teaser=true
  module_invoke('contemplate', 'nodeapi', $node, 'view', true); 
  
  $output .= $node->teaser;
 
  return $output;

We are passing in $node by reference so contemplate_nodeapi() will change the actual teaser in the $node object.
I have not tested this code, it is just pseudo code, it should work based on the understanding I get from http://api.drupal.org

jesuslm7’s picture

Hello jrglasgow!!

First thank you by your answer.

I try copy-paste your code in file /themes/darkgreen/template.php but continue show me as result the teaser as I have not define the teaser in contemplate.

Finally I find as to show the teaser that I define in contemplate. The code:

function museo_search_item($item, $type) {
  $output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']).'</a></dt>';
    
    $node = node_load($item['node']->nid);
    $output = node_view($node, TRUE, FALSE, FALSE);
	
  return $output;
}

Now I search as show the label "Read more".

Again Thank you very much.
I'm sorry by my bad inglish.

svihel’s picture

Good snipet, tested that and it is really working. (I doubted that at first, it looked to be too simple :] )
To port this to 6.x all you need to do is edit search-result.tpl.php, delete everything and leave just this:


print node_view(node_load($node_id), TRUE, FALSE, FALSE);

$node_id need to be passed there be editing your template.php and adding this function:


function mytheme_preprocess_search_result(&$variables) {
  $result = $variables['result'];
  $variables['node_id'] = $result['node']->nid;
  
  
}

omcateer’s picture

Thanks svihel,
This worked perfect for me too!

tngcas’s picture

The above code is throwing errors for me in the default user search? Any ideas why?

Error: Invalid argument supplied for foreach()... ...cck content.module on line 1284

I've looked at the cck forum and it seems to be related to the node type, which makes me wonder if this snippet only works for nodes and not users, but I'm not sure how to fix it?