Search code examples
javascriptnode.jsexpresspug

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.


Solution

  • conditional statement should do

    input(type='text', name='person[Name]', value= (person?(person.name?person.name:''):''))
    

    however, by design we can always pass a person? this way there is no comparison required. Code would be something like

    input(type='text', name='person[Name]', value= person.name)