You are here

fieldset.html.twig in Drupal 10

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.

File

core/themes/seven/templates/classy/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. */
  27. #}
  28. {%
  29. set classes = [
  30. 'js-form-item',
  31. 'form-item',
  32. 'js-form-wrapper',
  33. 'form-wrapper',
  34. ]
  35. %}
  36. <fieldset{{ attributes.addClass(classes) }}>
  37. {%
  38. set legend_span_classes = [
  39. 'fieldset-legend',
  40. required ? 'js-form-required',
  41. required ? 'form-required',
  42. ]
  43. %}
  44. {# Always wrap fieldset legends in a <span> for CSS positioning. #}
  45. <legend{{ legend.attributes }}>
  46. <span{{ legend_span.attributes.addClass(legend_span_classes) }}>{{ legend.title }}</span>
  47. </legend>
  48. <div class="fieldset-wrapper">
  49. {% if description_display == 'before' and description.content %}
  50. <div{{ description.attributes.addClass('description') }}>{{ description.content }}</div>
  51. {% endif %}
  52. {% if errors %}
  53. <div class="form-item--error-message">
  54. <strong>{{ errors }}</strong>
  55. </div>
  56. {% endif %}
  57. {% if prefix %}
  58. <span class="field-prefix">{{ prefix }}</span>
  59. {% endif %}
  60. {{ children }}
  61. {% if suffix %}
  62. <span class="field-suffix">{{ suffix }}</span>
  63. {% endif %}
  64. {% if description_display in ['after', 'invisible'] and description.content %}
  65. <div{{ description.attributes.addClass('description') }}>{{ description.content }}</div>
  66. {% endif %}
  67. </div>
  68. </fieldset>