0

I create a custom module that included hook_menu and hook_block_info and ... i wanna add a tpl to this module . here is my code :

        function hookmenu_menu() {
            $items['hookmenu'] = array(
                'title' => 'Soheil',
                'page callback' => 'hook',
                'type' => MENU_NORMAL_ITEM,
                'page callback' => 'myhook_page',
                'access arguments' =>array('administer content'),
            );
            return $items;
        }

        /*
         * page callback
         */
        function myhook_page(){

            return theme('my_custom_template');
        }

    /*
 * Implement hook_theme().
 */
function custom_example_theme(){
    return array(
        'my_custom_template' => array(

            'template' => 'custom-page',
        ),
    );
}

and i created a custom-page.tpl and wrote hello world .
result : i can see my page but i can't see hello world

thx

1 Answer 1

2

Your file needs to be named

custom-page.tpl.php

Note the .php extension. You might need to clear the caches to make that change show up

You also need either a variables or render element property as outlined in the docs

5
  • thx for your answer , i just add these : function custom_example_theme(){ return array( 'my_custom_template' => array( 'variables' => array( 'user' => NULL, 'node' => NULL, ), // file name will be custom-page.tpl.php 'template' => 'custom-page', ), ); } and clear the cash but nothing changed
    – user23811
    Jan 2, 2014 at 12:48
  • Hmm it should do, is the custom-page.tpl.php file in the root of the module?
    – Clive
    Jan 2, 2014 at 13:31
  • function custom_example_theme(){ return array( 'my_custom_template' => array( 'variables' => array( 'user' => NULL, 'node' => NULL, ), 'template' => 'custom-page') ); }
    – Cool
    Jan 2, 2014 at 17:51
  • @Clive yes i put it there
    – user23811
    Jan 2, 2014 at 20:52
  • @clive sorry for this question :is it important to put this this code bottom of codes or bottom of callback function ?
    – user23811
    Jan 2, 2014 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.