Drupal 7 - How to load a template file from a module?

前端 未结 5 568
时光说笑
时光说笑 2021-02-08 04:06

I am trying to build my own module in Drupal 7.

So I have created a simple module called \'moon\'

function moon_menu() {
  $items = array();
      $items         


        
5条回答
  •  南方客
    南方客 (楼主)
    2021-02-08 04:48

    /*
     * Implementation of hook_theme().
     */
    function moon_theme($existing, $type, $theme, $path){
      return array(
        'moon' => array(
          'variables' => array('content' => NULL),
          'file' => 'moon', // place you file in 'theme' folder of you module folder
          'path' => drupal_get_path('module', 'moon') .'/theme'
        )
      );
    }
    
    function moon_page(){
    
      // some code to generate $content variable
    
      return theme('moon', $content); // use $content variable in moon.tpl.php template
    }
    

提交回复
热议问题