If you want to theme a specific form, for example the edit form of a node type, then all you have to do is
/**
* Implements hook_theme().
*/
function THEMENAME_theme($existing, $type, $theme, $path) {
return [
// form id (weather it's an edit node for or a new node form)
'node_NODE_CONTENT_TYPE_edit_form' => [
'render element' => 'form',
],
];
}
Then create a twig file node-NODE-CONTENT-TYPE-edit-form.html.twig
and theme it like so:
{{ form.field_MACHINE_NAME_OF_FIELD }}
{{ form.field_MACHINE_NAME_OF_FIELD2 }}
...
{# this prints out the submit button #}
{{ form.actions }}
{# you need to have this for the form to work properly #}
{{ form|without('name', 'field_MACHINE_NAME_OF_FIELD2', 'field_MACHINE_NAME_OF_FIELD3') }}