data.html.twig 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. {% macro render_field(form, fields, scope) %}
  2. {% import _self as self %}
  3. {% for index, field in fields %}
  4. {%- set show_field = attribute(field, "input@") ?? field.store ?? true %}
  5. {% if field.fields %}
  6. {%- set new_scope = field.nest_id ? scope ~ field.name ~ '.' : scope -%}
  7. {{- self.render_field(form, field.fields, new_scope) }}
  8. {% else %}
  9. {% if show_field %}
  10. {%- set value = form.value(scope ~ (field.name ?? index)) -%}
  11. {% if value %}
  12. {% block field %}
  13. <div>
  14. {% block field_label %}
  15. <strong>{{ field.label|t|e }}</strong>:
  16. {% endblock %}
  17. {% block field_value %}
  18. {% if field.type == 'checkboxes' %}
  19. <ul>
  20. {% set use_keys = field.use is defined and field.use == 'keys' %}
  21. {% for key,value in form.value(scope ~ field.name) %}
  22. {% set index = (use_keys ? key : value) %}
  23. <li>{{ field.options[index]|t|e }}</li>
  24. {% endfor %}
  25. </ul>
  26. {% elseif field.type == 'radio' %}
  27. {% set value = form.value(scope ~ field.name) %}
  28. {{ field.options[value]|t|e }}
  29. {% elseif field.type == 'checkbox' %}
  30. {{ (form.value(scope ~ field.name) == 1) ? "GRAV.YES"|t|e : "GRAV.NO"|t|e }}
  31. {% elseif field.type == 'select' %}
  32. {% set value = form.value(scope ~ field.name) %}
  33. {% if value is iterable %}
  34. <ul>
  35. {% set use_keys = field.use is defined and field.use == 'keys' %}
  36. {% for key, val in value %}
  37. {% set index = (use_keys ? key : val) %}
  38. <li>{{ field.options[index]|t|e }}</li>
  39. {% endfor %}
  40. </ul>
  41. {% else %}
  42. {{ field.options[value]|t|e }}
  43. {% endif %}
  44. {% else %}
  45. {% set value = form.value(scope ~ field.name) %}
  46. {% if value is iterable %}
  47. <ul>
  48. {% for val in value %}
  49. {% if val is iterable %}
  50. <ul>
  51. {% for v in val %}
  52. <li>{{ string(v)|e }}</li>
  53. {% endfor %}
  54. </ul>
  55. {% else %}
  56. <li>{{ string(val)|e }}</li>
  57. {% endif %}
  58. {% endfor %}
  59. </ul>
  60. {% else %}
  61. {{ string(value)|e|nl2br }}
  62. {% endif %}
  63. {% endif %}
  64. {% endblock %}
  65. </div>
  66. {% endblock %}
  67. {% endif %}
  68. {% endif %}
  69. {% endif %}
  70. {% endfor %}
  71. {% endmacro %}
  72. {% import _self as macro %}
  73. {{ macro.render_field(form, form.fields, '') }}