As title, I would like to know how to the template syntax to keep the template result as string even if it looks like a number. For example if I enter in Developer Tools the template
{{ "+393331234567" }}
the result is 393331234567 and the type of result is number. How to change this template so that result is +393331234567 and the type a string?
The need to keep as string some template result, referencing states and script variables, come for some scripts and automation, where dropping the plus sign at the beginning of the string cause failures in subsequent service calls. An example (not the only one) is
3331234567 (without +39) is a valid input, the default country code (+39) will be used by subsequent gateway service
but if +39 or whatever intl code is included the plus should be keept to make gateway service understand there is already a country code
the logic seems too complex to replicate in a template in tens of place in automations and scripts
I’ve tried multiple different ways to make this work in the template editor, but I can also only get the result of number. I think this needs to be raised as a bug, if you explicitly cast to a string, it should not be getting converted to a number.
{% set w = "+3912345678901234567890"|string %}
{{ w }}
3.9123456789012346e+21
??
Even specifically casting to a string, the value is still automagically converted to a number, and now you can’t even get access to the original value.