0

I'm using the Link module to display a field that links to an external site. $snippet places this link (along with other fields) in a paragraph. The fields have no separation and the link doesn't work. I'd like to place $content in search-result.tpl to remedy this but everything I've tried has given me an error.

Someone mentions $result here which may be what I need.

I tried <?php print $result['field_lipsum']; ?> but it gives me Notice: Undefined index: field_lipsum in include() . . .

How can I place $content in search results instead of $snippet?

1 Answer 1

0

Define yourtheme_preprocess_search_result in your theme's template.php file. Do something like this:

function yourtheme_preprocess_search_result(&$variables) { //$variables['result']['node'] should contain the entire node object $variables['content'] = $variables['result']['node']->body[LANGUAGE_NONE][0]['value']; }

You should be able to use the variable $content inside search-result.tpl.php now.

14
  • Do I need to place function in front of that? I already have a yourtheme_preprocess_search_result. can I do yourtheme_preprocess_search_results? I tried adding it to that function but it gave me the error Notice: Undefined property: stdClass::$body in podliberty_preprocess_search_result()
    – James
    Apr 4, 2015 at 5:38
  • Yes, function needs to be in front of the function name.
    – Shawn Conn
    Apr 4, 2015 at 5:40
  • Okay I did it in a new function. (preprocess_search_resultS) then put <?php hide($content['comments']); hide($content['links']); print render($content); ?> in search-result.tpl but it doesn't show up
    – James
    Apr 4, 2015 at 5:43
  • What do you mean by should contain the entire node object?
    – James
    Apr 4, 2015 at 5:52
  • In the above example, it should just be setting a variable $content with the entire node content. You should be able to use print $content; to output it.
    – Shawn Conn
    Apr 4, 2015 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.