In the server action formatting menus, there are two operations that look much the same. I would like to understand the difference between them and when do I use each.
To access them, one must select a variable to bind, click on the formatter, and then right click on the variable name.
The first one is inside the Operation submenu. There are two options “?” and “:” that allow you to implement a ternary operation.
The other one is inside the Conditional submenu, and is call “Then”.
I’ve only vaguely noticed the ‘Then’ menu option. It wasn’t obvious how it works (at least to me), until I clicked it after @ben’s comment above. Now it makes sense - though the syntax looks slightly odd and unfamiliar:
At least, I think it makes sense. I can see it being a useful feature, so did a quick test. Based on this info icon:
I entered values to be returned:
… but it only returns ‘true’ or ‘false’. I was puzzled by the result:
. but it works if the ID is converted to a number (which obviously isn’t required in the case of test_1).
Given that it seems only ‘true’ or ‘false’ is returned, I’m not sure what the purpose of this option is.
Thank you for your answers and sorry for the late reply – I’ve been tied up and have not been able to look into it until now.
I’m not sure I understand the difference(s) between the two.
I understand the difference between an expression and a statement, but I’m not sure that the conditional “.then” that appears in the Formatter menu allows me to put an actual statement. The options presented are for expressions.
I believe that the one that allows me to put conditional statements in a server action is the one you access using the “Core Actions > Condition” .
So, frankly, I’m not sure what is the use case for the Formatter > Conditional > Then
I know I don’t get it and perhaps it’s because I am reading this the wrong way, but I think that the examples provided are used to set the value of a variable, which is the typical use case for the ternary operator.
Any further clarification on this point will be appreciated.