In *node--content_type.tpl.php* I can do the following:

print render($content);

Can I draw and hide field elements from a node's content in a similar way from $snippet; on search-result.tpl.php?

If not how do I gain greater control of the placement of images and body text in search results?

2 Answers 2


Can I draw and hide field elements from a node's content in a similar way from $snippet; on search-result.tpl.php?

You cannot, as $snippet is a string, not an render array. In fact, the default template used by Drupal contains the following code.

<?php if ($snippet): ?>
  <p class="search-snippet"<?php print $content_attributes; ?>><?php print $snippet; ?></p>
<?php endif; ?>

What you can do is implementing hook_preprocess_search_result() to change the content of $variables['snippet'] with the content you want to show. See template_preprocess_search_result() for a list of the variables passed to the preprocess function.

As you seem interested to alter what shown as result for a node search, you could also implement theme_search_result__node() as template_preprocess_search_result() use the following code to set the theme hook suggestions array.

$variables['theme_hook_suggestions'][] = 'search_result__' . $variables['module'];

The documentation for theme() says:

There are two special variables that these preprocess and process functions can set: 'theme_hook_suggestion' and 'theme_hook_suggestions'. These will be merged together to form a list of 'suggested' alternate theme hooks to use, in reverse order of priority. theme_hook_suggestion will always be a higher priority than items in theme_hook_suggestions. theme() will use the highest priority implementation that exists. If none exists, theme() will use the implementation for the theme hook it was called with. These suggestions are similar to and are used for similar reasons as calling theme() with an array as the $hook parameter (see below). The difference is whether the suggestions are determined by the code that calls theme() or by a preprocess or process function.


For me, the best way to have control over the display of each result was to comment out all of the default information that is rendered in search-result.tpl.php and instead load and render each result in its teaser form. I achieved this in the following way:

$view = node_view($result['node'], 'teaser');
print render($view);

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.