I am new to drupal, I am using drupal 8, I have develop a custom form by extending FormBase controller and i am trying to render it using a custom controller like below.

$form = $this->formBuilder->getForm('Drupal\xyz\Forms\XyzActionsForm',$parameter);

return [

This works fine form me. But now i also want custom html below this form so try below code

$form = $this->formBuilder->getForm('Drupal\xyz\Forms\XyzActionsForm',$parameter);

$form = render(form);

$form .= '<div>custom html </div>';

return [

But this didn't work for me, Can anyone let me know how to achieve this.

1 Answer 1


You have to use the power of render arrays.

For your example, I would use something like that :

$form_class = 'Drupal\xyz\Forms\XyzActionsForm';
$form = [
  'form' => $this->formBuilder->getForm($form_class, $parameter),
  'custom' => [
    '#type' => 'container',
    'inside' => [
      '#markup' => 'custom html', // Or use the power of render with html_tag type

return $form;

Then you can manage cache and other stuff on your render array and build your response with it.

  • That code work like a charm. Thanks for your quick reply on this
    – Udit Rawat
    Jul 23, 2017 at 11:52

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.