0

I'm trying to check whether a parameter was set when calling a Jade mixin. The following example does not work and I don't understand why.

mixin foo(bar)

  if bar
    - var text = 'a'
  else
    - var text = 'another'

  .hero-unit.macro-unit
    p This is #{text} mixin.


// Calling mixin:

+foo
+foo(bar)
+foo
+foo(bar)

Expected output:

This is a mixin.
This is another mixin.
This is a mixin.
This is another mixin.

Actual output:

This is a mixin.
This is a mixin.
This is a mixin.
This is a mixin.

I've also tried changing if bar to if (typeof(username) !== 'undefined') as suggested in this answer, but no dice. Where am I going wrong?

Community
  • 1
  • 1
Jerome Dahdah
  • 273
  • 2
  • 14

1 Answers1

1

When you are calling the mixin and you are passing in bar. This is an undefined variable. If you were to change it to.

+foo
+foo('bar')
+foo
+foo('bar')

You will find that you would get the expected result.

Noel Kriegler
  • 509
  • 3
  • 11