1

I am referring to document search-result.tpl.php on Drupal.org. Here they say $info_split['type'] has the node type information, but when I print in the file search-result.tpl.php in my theme folder, it does not print anything, as that key does not exist. So is there something that I should do to get this info?

4 Answers 4

1

I took a look into the code and it seems to be that is not implemented. So maybe it's a bug or just mistake in the documentation.

At least, you can reach your goal with the hook_node_search_result or even with template_preprocess_search_result if you don't want create a module.

For information, the $info_split for node is filled by node_search_execute that call the hook said above.

1

$info_split['type'] has been used in Drupal 6. It's gone in Drupal 7 so the documentation is not right.

Below my code for extending the $info_split array with type. I also extended it with the node revision timestamp to use custom format_date() in my template.

function template_preprocess_search_result(&$variables) { if (isset($variables['result']['node']->type)) { $variables['info_split']['type'] = $variables['result']['node']->type; } if (isset($variables['result']['node']->revision_timestamp)) { $variables['info_split']['revision'] = $variables['result']['node']->revision_timestamp; } }

0

This worked for me. I am using Apache Solr. $variables['result']['node']->type doesn't exist. $variables['result']['node']->bundle_name exists.

function my_theme_name_preprocess_search_result(&$variables) {
  if (isset($variables['result']['node']->bundle_name)) {
    $variables['info_split']['type'] = $variables['result']['node']->bundle_name;
  }
}
0

For Drupal 8 :

function theme_preprocess_search_result(&$variables) {
  if ($variables['result']['node']->getType()) {
      $variables['info_split']['node_type'] =$variables['result']['node']->getType();
  }
}

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.