Templates can be created or extended through a nextcloud app exposing a php class
Doc - Using Email templates
Source EmailTemplate.php