Search code examples
phpdrupaldrupal-7drupal-modulesdrupal-theming

How can I override path to my alternate template (.tpl.php) file, located within my module's folder?


I want to create a custom theme for a specific page. (e.g. www.domain.com/roster/%/home) For this purpose I've created the following file and placed it within the templates folder of my current theme (bartik): page--roster--home.tpl.php.

It overrides the default theme as desired, but I want to keep all files related to my module within its folder.

My question is, how can I place the file within my module's folder and still have Drupal 7 pick it up?


Solution

  • use Theme()

    return theme('some_theme_function_template', array('aValues' => $someArray));
    

    Then you need to use the theme hook like this:

    function my_module_name_theme() {
        return array(
            'some_theme_function_template' => array(
                'template' => 'mytheme',
            ),
        );
    }
    

    It now searches for mytheme.tpl.php in the root of you're module.