fieldset.html.twig

Same filename in this branch
  1. 11.x core/profiles/demo_umami/themes/umami/templates/classy/form/fieldset.html.twig
  2. 11.x core/themes/olivero/templates/form/fieldset.html.twig
  3. 11.x core/themes/stable9/templates/form/fieldset.html.twig
  4. 11.x core/themes/claro/templates/fieldset.html.twig
  5. 11.x core/themes/starterkit_theme/templates/form/fieldset.html.twig
  6. 11.x core/modules/system/templates/fieldset.html.twig
Same filename and directory in other branches
  1. 10 core/profiles/demo_umami/themes/umami/templates/classy/form/fieldset.html.twig
  2. 10 core/themes/olivero/templates/form/fieldset.html.twig
  3. 10 core/themes/stable9/templates/form/fieldset.html.twig
  4. 10 core/themes/claro/templates/fieldset.html.twig
  5. 10 core/themes/starterkit_theme/templates/form/fieldset.html.twig
  6. 10 core/modules/system/templates/fieldset.html.twig
  7. 9 core/profiles/demo_umami/themes/umami/templates/classy/form/fieldset.html.twig
  8. 9 core/themes/olivero/templates/form/fieldset.html.twig
  9. 9 core/themes/stable9/templates/form/fieldset.html.twig
  10. 9 core/themes/seven/templates/classy/form/fieldset.html.twig
  11. 9 core/themes/claro/templates/fieldset.html.twig
  12. 9 core/themes/bartik/templates/classy/form/fieldset.html.twig
  13. 9 core/themes/stable/templates/form/fieldset.html.twig
  14. 9 core/themes/starterkit_theme/templates/form/fieldset.html.twig
  15. 9 core/themes/classy/templates/form/fieldset.html.twig
  16. 9 core/modules/system/templates/fieldset.html.twig
  17. 8.9.x core/profiles/demo_umami/themes/umami/templates/classy/form/fieldset.html.twig
  18. 8.9.x core/themes/seven/templates/classy/form/fieldset.html.twig
  19. 8.9.x core/themes/claro/templates/fieldset.html.twig
  20. 8.9.x core/themes/bartik/templates/classy/form/fieldset.html.twig
  21. 8.9.x core/themes/stable/templates/form/fieldset.html.twig
  22. 8.9.x core/themes/classy/templates/form/fieldset.html.twig
  23. 8.9.x core/modules/system/templates/fieldset.html.twig
  24. main core/profiles/demo_umami/themes/umami/templates/classy/form/fieldset.html.twig
  25. main core/themes/olivero/templates/form/fieldset.html.twig
  26. main core/themes/stable9/templates/form/fieldset.html.twig
  27. main core/themes/claro/templates/fieldset.html.twig
  28. main core/themes/starterkit_theme/templates/form/fieldset.html.twig
  29. main core/modules/system/templates/fieldset.html.twig
  30. main core/themes/admin/templates/form/fieldset.html.twig

Theme override for a fieldset element and its children.

Available variables:

  • attributes: HTML attributes for the fieldset element.
  • errors: (optional) Any errors for this fieldset element, may not be set.
  • required: Boolean indicating whether the fieldset element is required.
  • legend: The legend element containing the following properties:
    • title: Title of the fieldset, intended for use as the text of the legend.
    • attributes: HTML attributes to apply to the legend.
  • description: The description element containing the following properties:
    • content: The description content of the fieldset.
    • attributes: HTML attributes to apply to the description container.
  • description_display: Description display setting. It can have these values:
    • before: The description is output before the element.
    • after: The description is output after the element (default).
    • invisible: The description is output after the element, hidden visually but available to screen readers.
  • children: The rendered child elements of the fieldset.
  • prefix: The content to add before the fieldset children.
  • suffix: The content to add after the fieldset children.

See also

template_preprocess_fieldset()

gin_preprocess_fieldset()

File

core/themes/admin/templates/form/fieldset.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for a fieldset element and its children.
  5. *
  6. * Available variables:
  7. * - attributes: HTML attributes for the fieldset element.
  8. * - errors: (optional) Any errors for this fieldset element, may not be set.
  9. * - required: Boolean indicating whether the fieldset element is required.
  10. * - legend: The legend element containing the following properties:
  11. * - title: Title of the fieldset, intended for use as the text of the legend.
  12. * - attributes: HTML attributes to apply to the legend.
  13. * - description: The description element containing the following properties:
  14. * - content: The description content of the fieldset.
  15. * - attributes: HTML attributes to apply to the description container.
  16. * - description_display: Description display setting. It can have these values:
  17. * - before: The description is output before the element.
  18. * - after: The description is output after the element (default).
  19. * - invisible: The description is output after the element, hidden visually
  20. * but available to screen readers.
  21. * - children: The rendered child elements of the fieldset.
  22. * - prefix: The content to add before the fieldset children.
  23. * - suffix: The content to add after the fieldset children.
  24. *
  25. * @see template_preprocess_fieldset()
  26. * @see gin_preprocess_fieldset()
  27. */
  28. #}
  29. {% set show_description_toggle = description_toggle and description.content %}
  30. {%
  31. set classes = [
  32. 'fieldset',
  33. attributes.hasClass('fieldgroup') ? 'fieldset--group',
  34. 'js-form-item',
  35. 'form-item',
  36. 'js-form-wrapper',
  37. 'form-wrapper',
  38. show_description_toggle ? 'help-icon__description-container',
  39. ]
  40. %}
  41. {%
  42. set wrapper_classes = [
  43. 'fieldset__wrapper',
  44. attributes.hasClass('fieldgroup') ? 'fieldset__wrapper--group',
  45. ]
  46. %}
  47. {%
  48. set legend_span_classes = [
  49. 'fieldset__label',
  50. attributes.hasClass('fieldgroup') ? 'fieldset__label--group',
  51. required ? 'js-form-required',
  52. required ? 'form-required',
  53. ]
  54. %}
  55. {%
  56. set legend_classes = [
  57. 'fieldset__legend',
  58. attributes.hasClass('fieldgroup') and not attributes.hasClass('form-composite') ? 'fieldset__legend--group',
  59. attributes.hasClass('form-composite') ? 'fieldset__legend--composite',
  60. title_display == 'invisible' ? 'fieldset__legend--invisible' : 'fieldset__legend--visible',
  61. ]
  62. %}
  63. {%
  64. set description_classes = [
  65. 'fieldset__description',
  66. show_description_toggle == 'invisible' ? 'visually-hidden',
  67. ]
  68. %}
  69. <fieldset{{ attributes.addClass(classes) }}>
  70. {% if show_description_toggle %}
  71. <div class="help-icon">
  72. {% endif %}
  73. {# Always wrap fieldset legends in a <span> for CSS positioning. #}
  74. {% if legend.title %}
  75. <legend{{ legend.attributes.addClass(legend_classes) }}>
  76. <span{{ legend_span.attributes.addClass(legend_span_classes) }}>{{ legend.title }}</span>
  77. </legend>
  78. {% endif %}
  79. {% if show_description_toggle %}
  80. {{ attach_library('gin/description_toggle') }}
  81. <button class="help-icon__description-toggle"></button>
  82. </div>
  83. {% endif %}
  84. <div{{ content_attributes.addClass(wrapper_classes) }}>
  85. {% if description.content and (description_display == 'before' or description_display_toggle == 'before') %}
  86. <div{{ description.attributes.addClass(description_classes) }}>{{ description.content }}</div>
  87. {% endif %}
  88. {% if inline_items %}
  89. <div class="container-inline">
  90. {% endif %}
  91. {% if prefix %}
  92. <span class="fieldset__prefix">{{ prefix }}</span>
  93. {% endif %}
  94. {{ children }}
  95. {% if suffix %}
  96. <span class="fieldset__suffix">{{ suffix }}</span>
  97. {% endif %}
  98. {% if errors %}
  99. <div class="fieldset__error-message">
  100. {{ errors }}
  101. </div>
  102. {% endif %}
  103. {% if description.content and description_display in ['after', 'invisible'] and description_display_toggle != 'before' %}
  104. <div{{ description.attributes.addClass(description_classes) }}>{{ description.content }}</div>
  105. {% endif %}
  106. {% if inline_items %}
  107. </div>
  108. {% endif %}
  109. </div>
  110. </fieldset>

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.