data.html.twig 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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]|e }}</li>
  24. {% endfor %}
  25. </ul>
  26. {% elseif field.type == 'checkbox' %}
  27. {{ (form.value(scope ~ field.name) == 1) ? "GRAV.YES"|t|e : "GRAV.NO"|t|e }}
  28. {% elseif field.type == 'select' %}
  29. {{ field.options[form.value(scope ~ field.name)]|e }}
  30. {% else %}
  31. {% set value = form.value(scope ~ field.name) %}
  32. {% if value is iterable %}
  33. <ul>
  34. {% for val in value %}
  35. {% if val is iterable %}
  36. <ul>
  37. {% for v in val %}
  38. <li>{{ string(v)|e }}</li>
  39. {% endfor %}
  40. </ul>
  41. {% else %}
  42. <li>{{ string(val)|e }}</li>
  43. {% endif %}
  44. {% endfor %}
  45. </ul>
  46. {% else %}
  47. {{ string(value)|e|nl2br }}
  48. {% endif %}
  49. {% endif %}
  50. {% endblock %}
  51. </div>
  52. {% endblock %}
  53. {% endif %}
  54. {% endif %}
  55. {% endif %}
  56. {% endfor %}
  57. {% endmacro %}
  58. {% import _self as macro %}
  59. {{ macro.render_field(form, form.fields, '') }}