3

I am using the Search file attachments module (which searches for text from pdf files after they are indexed), and everything works fine.

But I would like in Search result to display link to the content (where I uploaded the file) not link to the PDF itself, so that the user goes to that page and from there he can choose to see the PDF.

I am still new to Drupal, but from what I have read that I have to alter $search_results in search-results.tpl.php and use template_preprocess_search_results() to display what I want (not sure if this is the right way) or is there another way to this?

EDIT:

I found that I could edit search_file_attacments.module and there is the link attribute in $results[] I just have to figure out how to get nid (so I can get the url) from fid

1 Answer 1

3

First, I can't install the Search File Attachments module at this moment, but you can read at the module's page:

The module is based on the core search and no other module is required.

And I don't see any template page inside the module.

As in the search-result.tpl.php you will only have access to the $snippet variable, this is not a solution for you, because $snippet is a string, see the code inside search-result.tpl.php:

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

So your best bet should be implement the template_preprocess_search_results() in the template.php file of your theme.

See this example:

function THEME_preprocess_search_result(&$variables) {
    dpm($variables); //you need devel module to use dpm
}

Inside $variables['result'] you will have the values that you need to make your modification. See the dpm() output:

enter image description here

If you want modify the $snippet variable then change the value inside the function like this:

function THEME_preprocess_search_result(&$variables) {
  //searching the info that you need
  $variables['snippet'] = 'The new value';
}
1
  • about the search-result.tpl.php that is from core and i tought that i could overwrite this but as you said i have to this on the module itself so my bad . I will try this now and thanks for the explainations really helpful.
    – MePo
    Dec 21, 2015 at 6:30

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.