表单不在自定义模块内的自定义模板中呈现

时间:2018-05-31 12:31:46

标签: drupal-8

我想在覆盖html.html.twig的树枝模板中渲染我的表单 树枝模板名为html--resume--myform.html.twig

在我的表单类中我有这个代码

public function buildForm(array $form,FormStateInterface $form_state) 
{
    $form['#theme'] = ['html__resume__myform'];   
    $form['candidate_name'] = array(
        '#type' => 'textfield',
        '#title' => t('Candidate Name:'),
        '#required' => TRUE,
    );
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => $this->t('Save2'),
      '#button_type' => 'primary',
    );
    return $form
}

在我的resume.module文件中,我有这个自定义模板

function resume_theme() {
    return ['html__resume__myform' => ['render element' => 'form']];
} 

但我的表单未在html--resume--myform.html.twig中呈现 或我的$ form变量未传递给html--resume--myform.html.twig html--resume--myform.html.twig位于模板文件夹

0 个答案:

没有答案
相关问题