How to programmatically build a page and a form in the same page What I'd like to do is build a page with two things:


On one half of the page, custom markup with data from Drupal.
On the other half, a custom form also submitted to Drupal.


There are a lot of tutorials on how to programmatically build pages in D8 (create route, extend controller, return render array, etc.). There are also a lot of tutorials on how to programmatically build forms on D8 (create route, extend form base, return render array, etc.). However, I could not find any resource on how to build both onto the same page.

How would I go about doing this?
You must use the formBuilder, like this:

$render = [];
$render['elememt1'] = [
  '#type' =&gt; 'markup',
  '#markup' =&gt; t('Test'),
];
$render['element2'] = \Drupal::formBuilder()-&gt;getForm('Drupal\MY_MODULE\Form\MyFormClass');// The destination of your form.

return $render;