Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I create a module and mymodule.module file like this:

function mymodule_menu(){
    $items['mymodule/list']=array(
        'type'=>MENU_CALLBACK,
        'page callback'=>'mymodule_list_view',
    );
    return $items;
}

function mymodule_list_view(){
    theme('list_view');
}

function mymodule_theme($existing, $type, $theme, $path){
    return array(
        'list_view'=>array(
            'template'=>'mymodule_list',
            'type'=>'theme_engins',
        ),
    );
}

then I create templates file: mymodule_list.tpl.php

And I create a theme and create templates file: page--mymodule.tpl.php. Now when I access /mymodule/list, it will use page--mymodule.tpl.php to render the page.

My question is: how should I write page--mymodule.tpl.php to display the content in mymodule_list.tpl.php?

share|improve this question
1  
plz elaborate this –  monymirza Nov 27 '12 at 11:04
    
page--mymodule.tpl.php should just be a copy of page.tpl.php –  Alex Gill Nov 27 '12 at 11:45
    
I found that the content of mymodule_list.tpl.php was saved at the variable $page['content']['system_main']['main']['#markup'], so I think I should process this variable. –  solomon_wzs Nov 28 '12 at 1:56

1 Answer 1

up vote 1 down vote accepted

You don't need a customized page template file because you are using a template file for your theme. What you need to do is to fix your code, which should be as the following one.

function mymodule_menu() {
  $items['mymodule/list'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'mymodule_list_view',
    'access arguments' => array('access content'),
  );

  return $items;
}

function mymodule_list_view() {
  return theme('list_view');
}

function mymodule_theme() {
  return array(
    'list_view' => array(
      'template' => 'list-view',
    ),
  );
}

Notice that:

  • For the menu callback, you should define the access callback, and the access arguments, or the menu will not be visible to the users (except the user #1). By default, Drupal uses user_access() as access callback; in this case, you need to provide the permission string as access arguments.
  • The template filename must be equal to the theme name; the only acceptable difference is the underscores replaced by hyphens.
  • Your page callback needs to return its output, or print it. In the first case, the rendered page will contain all the output returned from Drupal, such as blocks; in the second case, the rendered page will just contain what your page callback prints.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.