So I am recently started working on front-end development, and have started messing around with making my own custom templates for modules. I have been able to get page related templates to work, but am having a problem getting form related templates to work.

This is for Drupal 7.

I have a form, like this (Its not quite this basic, but very similar and no special fields)

function mymodule_menu() {
  $items['admin/atavism/config'] = array(
    'title' => 'Configuration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('atavism_config'),
    'access arguments' => TRUE,

function atavism_config() {
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save Configuration',

  $form = theme('atavism_config_form', array('form',$form));
  return $form;

function atavism_theme() {
  return array(
    'atavism_config_form' => array(
      'template' => 'page--atavism-config-form',
      'path' => drupal_get_path('module','atavism') . '/theme',

And then I created the page--atavism-config-form.tpl.php. Inside of the form, I am using;

print render($form); 

I am doing the same thing for pages that are just content (normal pages with just text and markup for example, and no forms), and it's working as intended, but I am also doing the same thing for a couple of different forms I have, and I am running into two problems. Either #1, the form renders in the template, but ONLY the provided $form variables are available (so the form can't be submitted), or I get a white screen with a PHP error of 'Unsupported operand'.

It appears I may be doing something wrong with forms, but I can't figure out what. Could somebody please help me?

1 Answer 1


Adding the response I gave on Drupal.org:

The issue is that you are rendering the form with the theme() function, in the form definition. Instead, you need to identify the form as using a #theme, and let it be rendered downstream:

So remove this:

$form = theme('atavism_license_list_view', array('form' => $form));

And add this:

$form['#theme'] = 'atavism_license_list_view';

Link: https://www.drupal.org/forum/support/module-development-and-code-questions/2019-03-07/custom-template-file-for-modules#comment-13019068

  • Your solution worked wonderfully, thank you!
    – Ex0r
    Mar 13, 2019 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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