How do I theme a custom form? I generate a simple module "myformtest" with a simple Class form "MyformtestForm". I want to use a different theme for the form. 

I followed this great tutorial. I added a "_theme_suggestions_alter" hook in my "myformtest.module", I activated twig debugging and I loaded the form page. 



My "suggestion theme" is present and its name is "form--myformtest-form.html.twig". Then in my module directory:


I added a sub-directory "templates"
I added the twig file "form--myformtest-form.html.twig" in the sub-directory "drupal/modules/custom/myformtest/templates"


In the twig file, I added this simple code. (I copied it from the drupal/core/themes/classy/templates/form/form.html.twig and added the h1 html element for override)

&lt;h1&gt;TEST&lt;/h1&gt;
&lt;form{{ attributes }}&gt;
    {{ children }}
&lt;/form&gt;


I clear caches (drush cr) and I reloaded my form page. But the html element h1 ("TEST") doesn't appear! Where is my mistake? 

UP

I did it ! I added the hook theme in my .module file : 

function myformtest_theme($existing, $type, $theme, $path)
{
  return array(
    'form__myformtest_form' =&gt; array(
      'render element' =&gt; 'form',
      'template' =&gt; 'form--myformtest-form',
    ),
  );
}


But.... ! When I load my form page, the html element h1 "test" is displayed but not the form :/ I thinked my .twig file override the form.html.twig default theme. 



Did I miss something ? Why the form doesn't displayed, how can I fix it ? And how can I pass a custom array from my build method of form Class to my twig template ?
I've just been encountering a similar problem. And solved it like following.

In my MYMODULE.module file:

function MYMODULE_theme($existing, $type, $theme, $path) {

  return [
    'mythemename' =&gt; [
      'render element' =&gt; 'form',
      'template' =&gt; 'my-template-name',
    ],
  ];
}


In the $form:

$form['#theme'] = 'mythemename';


And finally in the my-template-name.html.twig template:

&lt;div class="someclass"&gt;
  {{ form }}
&lt;/div&gt;