Create a page template

Let's say I have this implementation hook_menu():

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

    $items['admin/recent-completions'] = array(
        'title' => 'Recent Completions (Last 100)',
        'page callback' => 'example_recent',
        'access callback' => user_access('Administer content'),
        'type' => MENU_NORMAL_ITEM,
        'weight' => -50
    );

    return $items;
}

How to create a page callback template instead of returning a string?

+5
source share
2 answers

You will need to implement the function hook_themeand specify the template file.

Then in your page callback you will need to call your theme function. Sort of...

function example_theme($existing, $type, $theme, $path) {
  return array(
    'recent_completion' => array(
      'render element' => 'elements', 
      'template' => 'recent-completions',
    ), 
  ...
}

function example_recent() {
  // Do some logic and processing here
  $render_array = array( /* array with parameters for the template */ );
  return theme('recent_completion', $render_array);
}
+5
source

I had the same question, but I did not know how to implement the hook_theme function. This is how it is done (at least in Drupal 6).

0
source

All Articles