-1

I have a Custom Composite Element key = "attendance_program_detail".

I am trying to create a computed Twig of Total hours.

The sub element is labeled Hours (Key = "hrs").

I don't know how to create a loop to add all the subelements that may be entered.

{{data.attendance_program_detail.hrs}}

Any assistance would be greatly appreciated.

Bert
  • 17
  • 3
  • Does this answer your question? [How to access dynamic variable names in twig?](https://stackoverflow.com/questions/24697313/how-to-access-dynamic-variable-names-in-twig) – DarkBee Jun 04 '23 at 18:04
  • No. But thank you for the suggestion. I need to loop through a custom composite element subelement key "hrs" to get a total. – Bert Jun 05 '23 at 09:46

1 Answers1

0

I found the following. Inserted the proper key names and it works fine.

{% for item in data.composite_element_key %}
  {% set sum = item.subelement_key + sum ?? 0 %}
  {% if loop.last %}{{ sum }}{% endif %}
{% endfor %}

Thanks!

Bert
  • 17
  • 3