Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline condition

  - 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.

like image 623
Patrick Avatar asked Dec 19 '11 16:12

Patrick


People also ask

What is inline conditional expression?

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".

What is inline statement?

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.

What is an inline function JavaScript?

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.


1 Answers

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')
...
like image 81
Romain Meresse Avatar answered Sep 18 '22 23:09

Romain Meresse