I have developed a custom search module that is working perfectly. Currently I am using the existing "search-results-tpl.php" and "search-result-tpl.php" for showing search results.

But I want to make my own custom template file for showing results and that template file should be inside my custom module directory. In this template I will be able to style my search results however I like.

Any suggestions on this?

Note: I have tried many contributed modules also, but they don't satisfy my requirements, so therefor I have started a custom module. But if you have any better solution, then feel free to point me to any of them.

  • that's a statement, not a question
    – Geoff
    May 22, 2015 at 7:43
  • You have quite a few questions about "search", and also about "search parameters". But mostly also with something like "only using core or custom modules". I think you should consider "some" contributed modules also that might offer a possible alternative to "enhance" the user experience, and to reduce the amount of code in your custom module(s). If you'd agree, please adapt your question accordingly. I'd be happy to suggest 2 such modules after you do ... Aug 12, 2015 at 6:25
  • hmm, actually I have tried many of them but doesn't fill my requirements then I have started it with custom module. But if you have any better solution then feel free to share.
    – WaQaR Ali
    Aug 12, 2015 at 6:31
  • I'd be happy to add an answer. But to avoid it would get flagged as "not an answer" (and then getting deleted), your question should somehow refer to contributed modules as a possible option to consider also. So if do add something like that, please "ping" me about it via an extra comment here ... I'll then add an answer with 2 specific modules, e.g. to style your search results however I like.. Aug 12, 2015 at 15:29
  • Dear @Pierre.Vriens don't worry about that. Please add your question.
    – WaQaR Ali
    Aug 12, 2015 at 15:59

3 Answers 3


By using the theme function I have got it working. Here is how it looks like:

 * Implements hook_theme().
 * Create custom theme and template files.
function mymodule_theme() {
  $themes = array(
    'my_search_result' => array(
      'variables' => array('result' => NULL, 'module' => NULL),
      'file' => 'mymodule.pages.inc',
      'template' => 'my-search-result',
    'my_search_results' => array(
      'variables' => array('results' => NULL, 'module' => NULL),
      'file' => 'mymodule.pages.inc',
      'template' => 'my-search-results',
  return $themes;
  • Can you enhance your answer a bit to explain (document) the code you included? Aug 12, 2015 at 6:15
  • ok, I will update my question for better understanding.
    – WaQaR Ali
    Aug 12, 2015 at 6:33
  • Can you also update your "answer" (the question seems clear enough to me, but I'm not sure I understand your "answer" ... Aug 12, 2015 at 18:31

Below are some suggestions for some contributed modules (as per your Note), for implementing some "custom search" features, and as an alternative for the "custom template" in your question.

Forena module

The Forena module can be used as a custom report writer, to be considered as an alternative to "custom searches".

You could take advantage of all sorts of features related to "Report Parameters". Refer to the Users in cities assigned to a state demo report for a very basic demo of such parameters.

Demo report Master Summary with drill down illustrates how you can "link" multiple reports together (also called "drill dow reports"). To experiment with it, click on any of the (green or yellow) bars in the barchart. You'll then be forwarded to another report corresponding to the bar you selected. If you'd rather want to use the links on the tabular report below it, that's an other option you could use. By the way: Forena is not just for (tabular) reports, but also for creating charts ... (using the open source library SVG Graph, which includes support for exporting charts to PDF ...).

After you'd become familiar with its FRX-language (to develop/design reports), you have the full xHTML spectrum available. To get an idea how its Custom Queries (SQLs) and/or Report Specifications look like, refer to my answer to the question "https://drupal.stackexchange.com/questions/152166/fetching-drupal-articles-tags-image-directly-from-database/154746#154746".

And don't forget you can write your custom (native) SQL queries ... with support for SQL parameters also.

Disclosure: I'm a co-maintainer of Forena,
I hope this does not violate the site's policy on self-promotion.

DataTables module

By using the DataTables module for displaying Views results, and especially the "Search box" widget of it, you basically don't have to worry anymore about what exactly the users want to search for. Refer to my answer to the question "What are my options to visualise a views table with many fields grouped in columns?" for AbitMORE details about this (amazing I think) module.

Forena's integration with the DataTables jQuery plugin

Forena also has a (straight forward) integration with the DataTables plugin (no need for the DataTables module). For an illustration of it, refer to these 2 demo samples:

  • With due respect, I think this is way beyond of the scope of the question. I'm not sure it belongs here. Aug 18, 2015 at 13:45

You may copy these templates from search module folder into your custom theme folder

  • but I want to make a template in my custom module not in theme folder
    – WaQaR Ali
    May 22, 2015 at 9:12
  • you can use hook_theme_registry_alter to do it
    – Andrew
    May 22, 2015 at 11:07

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.