Form / Block / Template I try to theme a custom form in my block.

Here my code :


  boutique.module


/**
 * Implements hook_theme().
 */
function boutique_theme() {

  return array(    
        'ajout_panier_form'=&gt; array(
            'render element' =&gt; 'form',
            'variables'=&gt; array(
                'form'=&gt; NULL,
            )
  )
  );
}



  AjoutPanierForm.php


/**
 * Class AjoutBlockForm.
 *
 * @package Drupal\boutique\Form
 */
class AjoutPanierForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'ajout_panier_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

        $form['#attributes']['oninput']='showPoids.value = poids.value';

        $form['poids'] = array(
            '#type' =&gt; 'range',
            '#title' =&gt; $this-&gt;t('Poids en gramme'),
            '#min' =&gt; 500,
            '#max' =&gt; 20000,
            '#default_value' =&gt; 500,
            '#step' =&gt; 100,
            '#attributes'=&gt;array('id'=&gt;array('poids')),
            '#description' =&gt; $this-&gt;t(""),
            '#required' =&gt; TRUE,
        );

        $form['showPoids']=array(
            '#type'=&gt;'markup',
            '#markup'=&gt;'&lt;output id="showPoids" for="poids"&gt;500&lt;/output&gt;'

        );

      $form['ajouter'] = array(
          '#type' =&gt; 'submit',
          '#value' =&gt; $this-&gt;t('Ajouter'),

      );


    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
drupal_set_message('ok');

  }



  AjoutPanierBlock.php


/**
 * Provides a 'AjoutPanierBlock' block.
 *
 * @Block(
 *  id = "ajout_panier_block",
 *  admin_label = @Translation("Block Ajout panier"),
 * )
 */
class AjoutPanierBlock extends BlockBase {


  /**
   * {@inheritdoc}
   */
  public function build() {

    $form = \Drupal::formBuilder()-&gt;getForm('Drupal\boutique\Form\AjoutPanierForm');

    $build = [
        '#theme' =&gt; 'ajout_panier_form',
        '#form' =&gt; $form,
  ];
    return $build;

  }

}


And my template :


  ajout-panier-form.html.twig


&lt;form{{ attributes }}&gt;  
    {{ form.poids }} {{ form.showPoids }}
    {{ form.form_build_id }} {# required #}
    {{ form.form_id }} {# required #}
    {{ form.ajouter }}
    {{ children }}
&lt;/form&gt;


My block call my template and my form is display.
But my submit doesn't call my method in my form controller where i put a

drupal_set_message('ok');


How add the actions form into template ? 
i have put {{ children }} but he doesn't work like the balise {{ form }} alone.
If you want to theme a form, better override the form.html.twig template, because you don't know what happens in the background of this template and you don't want to do this all from scratch in your own template.

So put the complete form in the block:

public function build() {
  return \Drupal::formBuilder()-&gt;getForm('Drupal\boutique\Form\AjoutPanierForm');
}


And copy the form.html.twig in your template and change it.