我尝试在自定义模块中制作自定义表单的模板,但我无法调用.tpl.php
这是我的主题template.php文件中的函数(位于: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',
),
);
}
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',
),
);
}
我的表单ID是:agendize_multistep_form(我使用drupal_set_message检查)
我的模板文件位于:
的Drupal /位点/所有/主题/ atheme /模板/ agendize_multistep_form.tpl.php
我把intentnaly设为空白tpl,以显示空白表格。 但我仍然拥有(即使有一个已清除的缓存)我的表单显示所有元素,就像我从未声明这个主题重写。
感谢您的帮助
答案 0 :(得分:1)
我希望以下代码可以帮助您。
<强> 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 /模板/ 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); ?>
请清除缓存并进行检查。