result search show teaser general but not teaser by contemplate
jesuslm7 - May 8, 2008 - 15:06
| Project: | Content Templates (Contemplate) |
| Version: | 5.x-2.0 |
| Component: | Code |
| Category: | support request |
| Priority: | critical |
| Assigned: | jesuslm7 |
| Status: | active |
Jump to:
Description
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.

#1
Contemplate doesn't actually change the teaser in the database, it uses the hook_nodeapi() to adjust the teaser.
<?php
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
$nodeby reference socontemplate_nodeapi()will change the actual teaser in the$nodeobject.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
#2
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.
#3
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:<?phpprint 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:
<?php
function mytheme_preprocess_search_result(&$variables) {
$result = $variables['result'];
$variables['node_id'] = $result['node']->nid;
}
?>