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

前端 未结 5 578
时光说笑
时光说笑 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:29

    You may use moon_menu, with hook_theme

     'desc information',
        'page callback' => '_moon_page',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
      );
      return $items;
    }
    
    function _moon_page() {    
      $fields = [];
      $fields['vars'] = 'var';
    
      return theme('os', compact('fields'));
    }
    
    /**
     * Implementation of hook_theme().
     */
    function os_theme() {
      $module_path = drupal_get_path('module', 'os');
    
      return array(
        'os' => array(
          'template' => 'os',
          'arguments' => 'fields',
          'path' => $module_path . '/templates',
        ),
      );
    }
    

提交回复
热议问题