How to pass a custom Form to a Twig template my problem is that my drupal 8 form is not getting rendered in twig template.

I created a form with build form method in drupal 8 when i tried it to pass in twig template it is not getting passed.for example my code is 

modulenameconfig.php

class modulenameConfigForm extends ConfigFormBase {

  /**

   * {@inheritdoc}

   */

  public function getFormId() {

    return 'modulename';

  } 
public function buildForm(array $form, FormStateInterface $form_state) {

    $form = parent::buildForm($form, $form_state);
    $config = $this-&gt;config('modulename.settings');


    $form['first_name'] = array(

      '#type' =&gt; 'textfield',

      '#title' =&gt; $this-&gt;t('First Name'),

      '#default_value' =&gt; $config-&gt;get('modulename.first_name'),

      '#required' =&gt; TRUE,

    );


    $form['last_name'] = array(
      '#type' =&gt; 'textfield',
      '#title' =&gt; t('Last Name'),
      '#default_value' =&gt; $config-&gt;get('modulename.last_name'),
      '#required' =&gt; TRUE,
    );
    return $form;

  }
 protected function getEditableConfigNames() {

    return [

      'modulename.settings',

    ];

  }
}


modulename.module

&lt;?php


namespace Drupal\modulename\Form;

use Drupal\Core\Form\ConfigFormBase;

use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_menu()
*/



function modulename_theme() {
  return array(
    'modulename_form' =&gt; array(
      'render element' =&gt; 'form',
      'template' =&gt; 'modulename-form',
      'base hook' =&gt; 'form'
    ),
  );
}


my twig file in templates folder

modluename-form.html.twig

{%
  set body_classes = [
    logged_in ? 'user-logged-in',
    not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class,
    node_type ? 'page-node-type-' ~ node_type|clean_class,
    db_offline ? 'db-offline',
  ]
%}                           


                           &lt;h2&gt;Personal Information&lt;/h2&gt;    
                                    &lt;form method="post"&gt;
                                        &lt;div class="form-group"&gt;
                                            &lt;label for="name"&gt;First Name&lt;/label&gt;
                                            &lt;div class="input-group"&gt;
                                              {{form.first_name}}

                                            &lt;/div&gt;
                                        &lt;/div&gt;
                                        &lt;div class="form-group"&gt;
                                            &lt;label for="name"&gt;Last Name&lt;/label&gt;

                                            &lt;div class="input-group"&gt;

                                                &lt;input type="text" class="form-control" name="lname" id="lastname" placeholder="Last Name" required&gt;

                                                &lt;span class="input-group-addon danger"&gt;&lt;span class="glyphicon icon-remove"&gt;&lt;/span&gt;&lt;/span&gt;
                                            &lt;/div&gt;
                                        &lt;/div&gt;  


any help will be greatly appriciated  help asap
This structure will not work with the autoloader right now - your namespaces and directory structure needs to follow these PSR-4 standards. (In particular, setting a namespace in your .module will cause Drupal to not find your hooks, which must be in the global namespace.)

I'm not sure I understand your use case fully, but it sounds like you want to:


Create a form.
Create a route that serves this form.
Render the form with a custom template.


For the first, your form class should be something like this (and must be saved in a file matching the class name under modulename/src/Form/{ClassName}.php):

namespace Drupal\modulename\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

class MyModuleConfigForm extends ConfigFormBase {

  public function getFormId() {
    return 'modulename_settings';
  }

  public function getEditableConfigNames() {
    return ['modulename.settings'];
  }

  public function buildForm(array $form, FormStateInterface $formState) {
    // build the form
    $form['...'] = [
      //...
    ]; 

    parent::buildForm();
    return $form;
  }

  public function submitForm(array $form, FormStateInterface $formState) {
    $this-&gt;config('modulename.settings')
      // set the values from the form
      -&gt;set('...', $formState-&gt;getValue('...'))
      -&gt;save();

    parent::submitForm($form, $formState);
  }

}


For the second part, you need a modulename.routing.yml file that looks something like this:

modulename.settings:
  path: '/admin/config/mymodule'
  defaults:
    _form: '\Drupal\modulename\Form\MyModuleConfigForm'
  requirements:
    _permission: 'administer site configuration'


(This is for admin configuration forms, since you mentioned ConfigFormBase. If you want a more general form and open it to anonymous users, extend FormBase instead and put _access: 'TRUE' in the route requirements.)

Finally, for the third part, you need to create your theme hook in modulename_theme(). (Your code already works, although the template key is superfluous as it matches the default.)

Then, modify the buildForm() as follows:

  public function buildForm(array $form, FormStateInterface $formState) {
    // build the form
    $form['...'] = [
      //...
    ]; 

    parent::buildForm();

    // *After* parent call.
    $form['#theme'] = 'modulename_form';

    return $form;
  }