Skip to main content
added 75 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

YouFor simple forms ...

... you can theme a form template by using {{ element }} instead of {{ children }}, see How to Create twig template files in drupal 8 for customizing user login,profile edit and forget password forms?. 

But this is not always the best approach, because it's difficult to include all form elements and metadata the form needs to operate.

ItFor complex forms ...

... it might be easier to add a custom forman additional template in a form alter hooklevel, which then only has to render the inner form elements, not the complete form:

/**
 * Implements hook_form_FORM_ID_alter() for \Drupal\user\RegisterForm.
 */
function mytheme_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
  $form['#theme'] = 'user_register_form';
}

The custom template needs to be registered in hook_theme, see. See How to render specific form elements from the *.theme file for a step-by-step example.

You can theme a form template by using {{ element }} instead of {{ children }}, see How to Create twig template files in drupal 8 for customizing user login,profile edit and forget password forms?. But this is not always the best approach, because it's difficult to include all form elements and metadata the form needs to operate.

It might be easier to add a custom form template in a form alter hook, which then only has to render the inner form elements, not the complete form:

/**
 * Implements hook_form_FORM_ID_alter() for \Drupal\user\RegisterForm.
 */
function mytheme_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
  $form['#theme'] = 'user_register_form';
}

The custom template needs to be registered in hook_theme, see How to render specific form elements from the *.theme file.

For simple forms ...

... you can theme a form template by using {{ element }} instead of {{ children }}, see How to Create twig template files in drupal 8 for customizing user login,profile edit and forget password forms?. 

But this is not always the best approach, because it's difficult to include all form elements and metadata the form needs to operate.

For complex forms ...

... it might be easier to add an additional template level, which only has to render the inner form elements, not the complete form:

/**
 * Implements hook_form_FORM_ID_alter() for \Drupal\user\RegisterForm.
 */
function mytheme_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
  $form['#theme'] = 'user_register_form';
}

The custom template needs to be registered in hook_theme. See How to render specific form elements from the *.theme file for a step-by-step example.

deleted 15 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

You can theme a form template by using {{ element }} instead of {{ children }}, see How to Create twig template files in drupal 8 for customizing user login,profile edit and forget password forms?. But this is not always the best approach, because it's difficult to include all form elements and metadata the form needs to operate.

It might be easier to add a custom form template in a form alter hook, which then is responsible for rendering only has to render the inner form elements, not the complete form:

/**
 * Implements hook_form_FORM_ID_alter() for \Drupal\user\RegisterForm.
 */
function mytheme_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
  $form['#theme'] = 'user_register_form';
}

The custom template needs to be registered in hook_theme, see How to render specific form elements from the *.theme file.

You can theme a form template by using {{ element }} instead of {{ children }}, see How to Create twig template files in drupal 8 for customizing user login,profile edit and forget password forms?. But this is not always the best approach, because it's difficult to include all form elements and metadata the form needs to operate.

It might be easier to add a custom form template in a form alter hook, which then is responsible for rendering only the inner form elements, not the complete form:

/**
 * Implements hook_form_FORM_ID_alter() for \Drupal\user\RegisterForm.
 */
function mytheme_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
  $form['#theme'] = 'user_register_form';
}

The custom template needs to be registered in hook_theme, see How to render specific form elements from the *.theme file.

You can theme a form template by using {{ element }} instead of {{ children }}, see How to Create twig template files in drupal 8 for customizing user login,profile edit and forget password forms?. But this is not always the best approach, because it's difficult to include all form elements and metadata the form needs to operate.

It might be easier to add a custom form template in a form alter hook, which then only has to render the inner form elements, not the complete form:

/**
 * Implements hook_form_FORM_ID_alter() for \Drupal\user\RegisterForm.
 */
function mytheme_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
  $form['#theme'] = 'user_register_form';
}

The custom template needs to be registered in hook_theme, see How to render specific form elements from the *.theme file.

Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

You can theme a form template by using {{ element }} instead of {{ children }}, see How to Create twig template files in drupal 8 for customizing user login,profile edit and forget password forms?. But this is not always the best approach, because it's difficult to include all form elements and metadata the form needs to operate.

It might be easier to add a custom form template in a form alter hook, which then is responsible for rendering only the inner form elements, not the complete form:

/**
 * Implements hook_form_FORM_ID_alter() for \Drupal\user\RegisterForm.
 */
function mytheme_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
  $form['#theme'] = 'user_register_form';
}

The custom template needs to be registered in hook_theme, see How to render specific form elements from the *.theme file.