1

I have a custom search form written in my custom-module. On submit, i have used do_search api and then I have made some modifications/customization with the results.

Now having my customized results, how can I render them?

Work so far--->

  • In custom-module.module

    function custom_module_search_ticket_form_submit($form, $form_state) {
       // do_search()
       //  customizations (in the sense, removed few results according to my requirements. Otherwise the result-object/array format is same as of core search results) 
    
        return theme('rootcandy_my_search_results', $results, $type);
    }
    
    function custom_module_theme() {
      return array(
        'rootcandy_my_search_result' => array(
          'arguments' => array('result' => NULL, 'type' => NULL),
          'template' => 'rootcandy-my-search-result',
        ),
        'rootcandy_my_search_results' => array(
          'arguments' => array('results' => NULL, 'type' => NULL),
          'template' => 'rootcandy-my-search-results',
        ),
      );
    }
    
  • Rootcandy is the theme I have used. In rootcandy's template.php

    function rootcandy_preprocess_rootcandy_my_search_results (&$vars)  {
      // copied lines from core search module's search.pages.inc function template_preprocess_search_results(&$vars)
    }
    
    function rootcandy_preprocess_rootcandy_my_search_result (&$vars) {
      // copied lines from core search module's search.pages.inc function template_preprocess_search_result(&$vars) 
    }
    
  • Under rootcandy theme folder, Added below tpl.php files

    rootcandy-my-search-results.tpl.php  (copied from core search's search-results.tpl.php)
    rootcandy-my-search-result.tpl.php   (copied from core search's search-result.tpl.php)
    

Now I have done this much, clearing cache, after everything; Submitting my custom-search-form renders nothing, other than the form. When I print my customized results, they are fine. Theming part is not working.

Where is the mistake? Plz help !

1 Answer 1

0

Whatever u have done so far is correct. Only thing left now is to render the content from ur preprocess 'rootcandy_preprocess_rootcandy_my_search_results' to ur 'rootcandy-my-search-results.tpl.php'. U have to start debugging in this way.

  1. Check ur $vars['form'] contains ur form values in 'rootcandy_preprocess_rootcandy_my_search_results'

  2. create a variable in preprocess and try using it in ur rootcandy-my-search-results.tpl.php. Eg: $vars['testing'] = "this is to confirm that variable is working in rootcandy-my-search-results.tpl.php"

  3. if you print $testing in ur rootcandy-my-search-results.tpl.php and it gives "this is to confirm that variable is working in rootcandy-my-search-results.tpl.php" Which means its working fine.

  4. Then you can pass ur form results to the tpl file. Eg: $vars['result'] = drupal_render($vars['form']['result']);

Try this. Ur first goal will be making sure u can get ur preprocess values in ur tpl file.

1
  • please don't add short form like "u", "ur". add it in full form.
    – Bala
    Commented Dec 15, 2013 at 8:08

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.