- if (typeof(person) == 'undefined')
input(type="text", name="person[Name]")
- else
input(type="text", name="person[Name]", value="#{person.Name}")
Is there any way to write this inline? I have an option select and I don't want to do a conditional statement for 30+ values to select the right option.
It is commonly referred to as the conditional operator, inline if (iif), or ternary if. An expression a ? b : c evaluates to b if the value of a is true, and otherwise to c . One can read it aloud as "if a then b otherwise c".
An inline PERFORM is an imperative statement that is executed in the normal flow of a program; an out-of-line PERFORM entails a branch to a named paragraph and an implicit return from that paragraph.
An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. This eliminates call-linkage overhead and can expose significant optimization opportunities.
You could use mixins
mixin safeInput(person, property)
- if (typeof(person) == 'undefined')
input(type="text", name="person[#{property}]")
- else
input(type="text", name="person[#{property}]", value="#{person[property]}")
Then
mixin safeInput(person, 'Name')
mixin safeInput(person, 'Email')
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With