Search code examples
htmlpugpugjs

Adding if/else statements to Pug (ex-Jade) mixins?


How can I add if/else statement to mixin for adding checked attribute to my first radio input?

mixin tab-header(name, id)
  input(type='radio' name='tabs' id=id checked)
  label(for=id) name
+tab-header('Monday', 'toggle-monday')
+tab-header('Tuesday', 'toggle-tuesday')
+tab-header('Wednesday', 'toggle-wednesday')
+tab-header('Thursday', 'toggle-thursday')

Solution

  • Just add one more parameter:

    mixin tab-header(name, id, checked)
      input(type='radio' name='tabs' id=id checked=checked)
      label(for=id) name
    
    +tab-header('Monday', 'toggle-monday', true)