Search code examples
pug

jade doesn't let me use include #{variable} in a mixin


I want to print an include as a result of a mixin, but jade wants to parse the include when it first reads the mixin.

mixin myHeader(name)
  div#{name} 
    h1 #{name}
      include #{name}


!!! html
  html
    head
    body
      +myHeader(#home)
      +myHeader(#schedule)
      +myHeader(#map)
      +myHeader(#lecturers)

I think the error is telling me jade can't find #{name} to include in the mixin.

ENOENT, no such file or directory '#{name}.jade'


Solution

  • Jade does not support variables in includes. A workaround is demonstrated in this stackoverflow question