Form in custom module using Controller: The HTML tag form isn't present in Twig I'm trying to render limited user edit form on custom page using Drupal Controller.
In the routing.yml I defined _controller, I do not want to use _form.
I want to display on the form e.g. only timezone field, but not the rest. And I'm not able to achieve it. I can render this field, other fields like form_build_id, form_id, form_token
But form html tag is not rendered at all.
It works only if I display the whole form with {{ form.form }}.
This is the content of the files I am using.
my_module.info.yml
name: 'My module'
type: module
description: 'my module'
core_version_requirement: ^8.8 || ^9

my_module.routing.yml
my_module.mymodule_controller_view::
  path: '/my-module'
  defaults:
    _controller: '\Drupal\my_module\Controller\MymoduleController::view'
    _title: 'My module'
  requirements:
    _permission: 'access content'

my_module.module
function my_module_theme($existing, $type, $theme, $path)
{
    $templates = array(
        'my_module_form' =&gt; [
            'render element' =&gt; 'form',
        ],
    );

    return $templates;
}

MymoduleController.php
namespace Drupal\my_module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\user\Entity\User;

class MymoduleController extends ControllerBase
{

    public function view()
    {
        $data['header'] = [
            '#type' =&gt; 'markup',
            '#markup' =&gt; '&lt;h1&gt;HEADER&lt;/h1&gt;',
        ];

        $user = User::load(\Drupal::currentUser()-&gt;id());
        $formObject = \Drupal::entityTypeManager()
            -&gt;getFormObject('user', 'default')
            -&gt;setEntity($user);

        $form = \Drupal::formBuilder()-&gt;getForm($formObject);

        $data['form'] = [
            '#theme' =&gt; 'my_module_form',
            'form' =&gt; $form,
        ];

        $data['footer'] = [
            '#type' =&gt; 'markup',
            '#markup' =&gt; '&lt;h3&gt;footer&lt;/h3&gt;',
        ];

        return $data;
    }
}

my-module-form.html.twig
&lt;div&gt;TWIG TEMPLATE&lt;/div&gt;

{{ form.form.timezone }}
{{ form.form.form_build_id }}
{{ form.form.form_token }}
{{ form.form.form_id }}
{{ form.form.actions }}
This is not working, you can't use a form template in a controller. You have to assign the template to $form['#theme'] when building the form or in a form alter hook. Then it gets used by formBuilder()-&gt;getForm() automatically.
See for example seven_form_node_form_alter():
$form['#theme'] = ['node_edit_form'];

and the corresponding twig file for a two column layout:
core/themes/seven/templates/node-edit-form.html.twig
{#
/**
 * @file
 * Theme override for a node edit form.
 *
 * Two column template for the node add/edit form.
 *
 * This template will be used when a node edit form specifies 'node_edit_form'
 * as its #theme callback.  Otherwise, by default, node add/edit forms will be
 * themed by form.html.twig.
 *
 * Available variables:
 * - form: The node add/edit form.
 *
 * @see seven_form_node_form_alter()
 */
#}
&lt;div class=&quot;layout-node-form clearfix&quot;&gt;
  &lt;div class=&quot;layout-region layout-region-node-main&quot;&gt;
    {{ form|without('advanced', 'footer', 'actions') }}
  &lt;/div&gt;
  &lt;div class=&quot;layout-region layout-region-node-secondary&quot;&gt;
    {{ form.advanced }}
  &lt;/div&gt;
  &lt;div class=&quot;layout-region layout-region-node-footer&quot;&gt;
    &lt;div class=&quot;layout-region-node-footer__content&quot;&gt;
      {{ form.footer }}
      {{ form.actions }}
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


Form modes
A different approach would be to configure a form mode in UI containing only the field you want and then use it in your controller:
    $formObject = \Drupal::entityTypeManager()
        -&gt;getFormObject('user', 'custom_form_mode')
        -&gt;setEntity($user);

See How do I load a form with a specific form display (form mode)?