Same filename in this branch
  1. 10 core/modules/system/templates/form-element-label.html.twig
  2. 10 core/themes/claro/templates/form-element-label.html.twig
  3. 10 core/themes/stable9/templates/form/form-element-label.html.twig
  4. 10 core/themes/starterkit_theme/templates/form/form-element-label.html.twig
  5. 10 core/profiles/demo_umami/themes/umami/templates/components/form/form-element-label.html.twig
Same filename and directory in other branches
  1. 8.9.x core/modules/system/templates/form-element-label.html.twig
  2. 9 core/modules/system/templates/form-element-label.html.twig

Default theme implementation for a form element label.

Available variables:

  • title: The label's text.
  • title_display: Elements title_display setting.
  • required: An indicator for whether the associated form element is required.
  • attributes: A list of HTML attributes for the label.

See also

template_preprocess_form_element_label()

2 theme calls to form-element-label.html.twig
Label::getInfo in core/lib/Drupal/Core/Render/Element/Label.php
Returns the element properties for this element.
template_preprocess_form_element in core/includes/form.inc
Returns HTML for a form element.

File

core/modules/system/templates/form-element-label.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for a form element label.
  5. *
  6. * Available variables:
  7. * - title: The label's text.
  8. * - title_display: Elements title_display setting.
  9. * - required: An indicator for whether the associated form element is required.
  10. * - attributes: A list of HTML attributes for the label.
  11. *
  12. * @see template_preprocess_form_element_label()
  13. *
  14. * @ingroup themeable
  15. */
  16. #}
  17. {%
  18. set classes = [
  19. title_display == 'after' ? 'option',
  20. title_display == 'invisible' ? 'visually-hidden',
  21. required ? 'js-form-required',
  22. required ? 'form-required',
  23. ]
  24. %}
  25. {% if title is not empty or required -%}
  26. <label{{ attributes.addClass(classes) }}>{{ title }}</label>
  27. {%- endif %}

Related topics