0

I have created a custom module that adds some form elements to nodes of specific content types. Another part of this module requires a specific formatting output of data that is a little more complex than using $form[''].

How can I tell my module that for a specific function, it should load a certain template file?

1

Template files are associated with theme functions. To use a template, the theme function that is declared in hook_theme() must report that it is using a template file, and this is done adding the "template" property.
For example, the following definition used from the Node module says to Drupal that for the "node" theme function, it needs to use the "node.tpl.php" template file; every times a module calls theme('node', …), Drupal will know to use that template.

function node_theme() {
  return array(
    'node' => array(
      'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE), 
      'template' => 'node',
    ), 
    // …
  );
}

For a page that is visible on http://example.com/parcels, Drupal checks for a template file named "page-parcels.tpl.php" exists, and use it in that case. The template files are looked in the directory of the currently set theme, though; this mean that the template is not found if it is in the directory of a module.

  • I understand how that function works but I think im getting confused as to the whole process. For example, within my module, I define a menu item say "Parcels" with a callback to mymodule_parcels which displays a list of parcels. The user is then able to access this page from domain.com/parcels - I want only that particular page/function to use a specific template such as parcels.page.tpl.php (or whatever) - does that make sense? Im sure im missing something in all of this – Tim Sep 15 '11 at 6:52
  • I have updated my answer. – kiamlaluno Sep 15 '11 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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