I'm using this in a computed_twig element and it's fully working when I test it in this fiddle but only works correctly for value "0" while gives "high" for everything else (e.g. 0.1, 0.4, 0.5, etc) when in my webform!
q# are values of radio input type elements. I tried several variations all to no avail! Thanks
Edit: updated my question and added a minimal sample of my webform. I didn't post this at the twig stack because it's working on fiddle and only when in my Drupal Webform it's malfunctioning. I tried with and without the number_format filter kindly suggested by @cilefen but still no change in the result. I'd exhausted my search online and read and saw examples on official Twig and other pages and still couldn't figure out what I'm doing wrong! I don't know much about twig apart from what I learn on the go to meet my special need at the time.
Note: I changed "TsC" in my previous post version to TCount to be more meaningful. Also, it's on a shared host with PHP 7.4 still.
Thanks to everyone who commented so far and I wish that whoever downvoted me straight away after posting explained why so I could learn for future posts.
qp1:
'#type': wizard_page
'#title': 'Part I'
'#open': true
ps1:
'#type': details
'#title': title...
'#required': true
'#attributes':
class:
- qp1_1
q1:
'#type': radios
'#title': q1.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q2:
'#type': radios
'#title': q2....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q3:
'#type': radios
'#title': q3.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q4:
'#type': radios
'#title': q4.......
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q5:
'#type': radios
'#title': q5........
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q6:
'#type': radios
'#title': q6.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q7:
'#type': radios
'#title': q7....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q8:
'#type': radios
'#title': q8.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q9:
'#type': radios
'#title': q9.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q10:
'#type': radios
'#title': q10.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q11:
'#type': radios
'#title': q11....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q12:
'#type': radios
'#title': q12.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q13:
'#type': radios
'#title': q13.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q14:
'#type': radios
'#title': q14.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
'#required': true
q15:
'#type': radios
'#title': q15......
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
q16:
'#type': radios
'#title': q16.....
'#options':
- 'option 1 with value 0'
- 'option 2 with value 1'
- 'option 3 with value 2'
- 'option 4 with value 3'
'#required': true
qs_count:
'#type': computed_twig
'#title': 'Total Count'
'#wrapper_attributes':
class:
- score_qp_1
'#template': 'Total Count: {% set TCount = (data.q1 + data.q2 + data.q3 + data.q4 + data.q5 + data.q6 + data.q7 + data.q8 + data.q9 + data.q10 + data.q11 + data.q12 + data.q13 + data.q14 + data.q15 + data.q16)|number_format(0) %} {{ TCount }} <br /> Ratio: {{ TCount / 16 }} <br /> {% if TCount == 0 %} Great {% elseif TCount > 0 and TCount < 0.5 %} Low {% elseif TCount >= 0.5 and TCount < 0.7 %} Moderate {% elseif TCount >= 0.7 %} High {% endif %}'
'#ajax': true
TsC
isn't what you expect it to be, which you could confirm by simply printing it?|number_format
filter on string operands which are to be used in computations.