How to use preprocess function for custom templates defined in hook_theme? I have a custom module that i've created and I have set the theme template like this:

/**
 * Implemtnation of hook_theme()
 */
function custom_slider_theme($existing, $type, $theme, $path) {
    return array(
        'custom_slider' =&gt; array(
            'variables' =&gt; array('nodes' =&gt; NULL),
            'template' =&gt; 'custom_slider',
        ),
    );
}


This is all working fine.

What I can't find is how to load a css file for that template so when custom_slider.tpl.php is loaded the relevent css file is loaded. I don't need that css loaded on every page. I would rather call drupal_add_css() only when it's needed.

I used below approach, but it's not working.

function ModuleName_preprocess_TemplateName(&amp;$vars) {
      drupal_add_css(drupal_get_path('module', 'custom_slider') . '/file.css');
    }


Also I added 

'preprocess functions' =&gt;array('ModuleName_preprocess_TemplateName'),


in hook_theme, where I defined my templates, kindly suggest the right way to do it.

Any help with this is very much appreciated.
Drupal will automatically call hook_preprocess_[template] for each template defined in hook_theme. 

e.g:

MODULE_preprocess_custom_slider(&amp;$variables){}


Should be called by default. If not, then clear your cache to be sure the preprocess function is registered.

Fun fact is preprocess functions are called for theme functions as well, e.g theme_item_list calls hook_preprocess_item_list prior to rendering.