【发布时间】:2017-12-08 05:26:46
【问题描述】:
我目前正在使用 drupal 8,我已经使用表单 api 创建了表单,
Module目录下的以下代码
// module/src/Form/ContributeForm
class ContributeForm extends FormBase {
public function getFormId() {
return 'amazing_forms_contribute_form';
}
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#required' => TRUE,
);
$form['video'] = array(
'#type' => 'textfield',
'#title' => t('Youtube video'),
);
$form['video'] = array(
'#type' => 'textfield',
'#title' => t('Youtube video'),
);
$form['develop'] = array(
'#type' => 'checkbox',
'#title' => t('I would like to be involved in developing this
material'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}
现在我需要在下面的树枝模板中渲染上面的变量
//themes/page.html.twig
<body>
{{form.title}}
{{form.video}}
{{form.video}}
</body>
twig 将在主题文件夹下。是否可以在 page.html.twig 文件中获取变量??
【问题讨论】: