By point-1 on
I would like to display my search results as teaser list but can't find a way to do that at the moment.
There is a template file search-result.tpl.php (http://api.drupal.org/api/file/modules/search/search-result.tpl.php/6), but available variables do not include $node object or at least $nid, so I could load that node to display what I want.
Is there a way to do it?
Comments
Well
Well http://api.drupal.org/api/function/node_search/6 certainly does return complete node objects - so in principle it's just a matter of hooking in somewhere between that and the search results template ...
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Ahhh, maybe the point is
Ahhh, maybe the point is that http://api.drupal.org/api/function/template_preprocess_search_result/6 doesn't give you a $node ... but is it present, in your template, in $result['node']?
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Yes, it's present there, but
Yes, it's present there, but I don't know how to override template_preprocess_search_result() because I don't want to override the core.
Can you just use
Can you just use $result['node']->teaser in your template? (You might need to a bit of processing on it to apply input formats etc.) Or use something like
node_view($result['node'], TRUE, FALSE, FALSE)- see http://api.drupal.org/api/function/node_view/6.gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Great, I can use
Great, I can use $result['node'] in tpl.php. Thanks!
:)
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
tpl.php
Point,
Which tpl file are you referring to?
-Alex
http://api.drupal.org/api/fil
http://api.drupal.org/api/file/modules/search/search-result.tpl.php/6.
You may want to copy it to your theme's directory and modify it there.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
I'm close but still need help
I used
<?php print $result['node']->teaser ?>This has proven to be the most help for me thus far. Now at least I have the teasers showing up on the search page, but I am still having a few more problems if you can help please.I am very much a novice at this and I have been trying to resolve this for a few months as you can see from my previous posts. From other user posts I can also see that this is very common inquiry for others like me who need the images from their teasers to show, art gallery and ecommerce sites especially. But with all of these advanced php coders and Drupal experts there does not seem to be anyone who knows how to do this. Any help would be truly appreciated.
Thank you
Well for starters you need to
Well for starters you need to sort out your CSS. It looks like you are manually adding style.css to your page.tpl.php, but it is also output automatically by Drupal in compressed form. Hence all your CSS style rules are duplicated.
So turn of CSS compression for now, and then you'll need to examine your page source to check which stylesheets are being multiply loaded. Only turn CSS compression on when everything is working.
gpk
----
www.alexoria.co.uk
Hello, I can't make it work
Hello, I can't make it work :(
Do you just have to remplace in the search-result.tpl.php:
to
print $result['node']->teaserI'm using the core serach module.
Thanks :)
Having Trouble
I am having a bit of trouble getting this to work. If I understand correctly, my search-result.tpl.php should look like:
But what goes into function MYTHEME_preprocess_search_result(&$variables)?
What I noticed ...
... is that modifying the search-result.tpl.php works for the core searches (/search/node). However, I am using Apache Solr and searches performed at (/search/apachesolr_search) are not affected by the changes in search-result.tpl.php with this method.
We just setup apache solr on a site here
and I encountered the same problem when I copied the search-result.tpl.php to my theme directory and modified it there. However, changes made to the original file in the searce module directory works.
So for now I just backed up the original search-result.tpl.php and have my modified version in the search module directory.
EDIT: Ahh, I see what you meant now. $result['node']->teaser isn't available when using Solr. :/
EDIT2:
Here's how I fixed it when using Apache Solr.
(search-result.tpl.php)
Øyvind Strømsvik
Tech lead | Frontkom AS
https://frontkom.com/
It finally works!!
After a couple days of no success, I finally gave up. Thank you very much for finding the solution!!
minor change
Almost perfect but.. in order to make it work I had to change "$nid = $result['node']->getField('nid');" to "$nid = $result['node']->nid;". I am using D6.16, MySQL 5.1.36 and Apache 2.2.11. Thanks
To summarize all of the
To summarize all of the above, for Drupal 6.x:
- Use this for regular search:
- Use this if using Apache SOLR search:
Both go in search-result.tpl.php in your theme folder.
Are both snippets supposed to
Are both snippets supposed to be the same? Just wanted to check.
I'm also confused seeing....
....the same code posted twice for two different applications. I'm personally trying to display teasers as search results and finding it extremly challenging. I'm a bit surprised this isn't an option within core by default.
Using Lucene search (although as I understand it, in terms of rendering results I'm essentially using core search). Drupal 6.
The first snippet should have
The first snippet should have been this:
This worked great. Thanks for
This worked great. Thanks for the snippet.
I want to highlight the searched terms in the teaser using search_excerpt (http://api.drupal.org/api/drupal/modules--search--search.module/function...)
how can I get the searched terms in search-result.tpl.php?
Cheers,
TechNikh
In 30 seconds set up Automated Visual testing of your website. Zero coding. https://drupal.org/project/drulenium
Ever dreamed of styling your view, We have a solution for you. https://drupal.org/project/views_stylizer
Worked like a charm. THANK
Worked like a charm. THANK YOU!
Slight change 6.22 and ApacheSolr 6.1.5
I had an error after upgrading to core 6.22 and solr 6.1.5, here's the modified code I used to fix my error (Undefined class getField) :
Working code:
Drupal 7
This is for Drupal 7.
Apache SOLR search:
Add to search-result.tpl.php that you have copied in your theme folder:
For Drupal 7
...this should be the way to handle search result display:
http://drupal.org/node/1166114
But it seems to be bugged. Atm.