Drupal 7 theme not called?

116 views Asked by At

I tried to make a template form my custom form made in a custom module, but i dont manage to call the .tpl.php

Here is my function in my theme template.php file (which is under : drupal/sites/all/themes/atheme) :

 function atheme_theme() {
 return array(
  // Defines the form ID as a theme hook.
   'agendize_multistep_form' => array(
    // Specifies 'form' as a render element.
  'render element' => 'form',
    'path' => drupal_get_path('theme', 'atheme') . '/templates',
'template' => 'agendize_multistep_form',
),
  ); 
}

My form id is : agendize_multistep_form (I checked with drupal_set_message)

An my template file is under:

drupal/sites/all/themes/atheme/templates/agendize_multistep_form.tpl.php

I put intentionnaly a blank tpl in order to have a blank form displayed. But I still have (even with a cleared cache) my form with all elements displayed , like if i never declared this theme overriding.

Thx for your help

1

There are 1 answers

1
AudioBubble On

I hope the below code helps you.

atheme/template.php:

function atheme_theme($existing, $type, $theme, $path) {
    $items['agendize_multistep_form'] = array(
        'render element' => 'form',
        'template' => 'agendize_multistep_form',
        'path' => drupal_get_path('theme', 'atheme') . '/template',
    );

    return $items;
}

agendize_multistep_form():

function agendize_multistep_form($form, &$form_state) {
    $form['first_name'] = array(
        '#type' => 'textfield',
        '#attributes' => array('placeholder' => t('First name')),
    );
    $form['last_name'] = array(
        '#type' => 'textfield',
        '#attributes' => array('placeholder' => t('Last name')),
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
    );
    return $form;
}

atheme/template/agendize_multistep_form.tpl.php:

<div class="agendize-form">
    <div class="firstname">
        <?php print render($form['first_name']); ?>
    </div>
    <div class="lastname">
        <?php print render($form['last_name']); ?>
    </div>
    <div class="submit">
        <?php print render($form['submit']); ?>
    </div>
</div>

<!-- Render any remaining elements, such as hidden inputs (token, form_id, etc). -->
<?php print drupal_render_children($form); ?>

Kindly clear the cache and have a check.