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.