问题
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'
回答1:
Jade does not support variables in includes. A workaround is demonstrated in this stackoverflow question
回答2:
Maybe you can use mixins made in different files instead
like
// popups.pug
mixin temperature()
h3 temperature
Included in another file worked fine for me
//modal-content.pug
include popups
mixin modal-content-popup(component)
.modal-content
.modal-content__settings
+#{component}()
.modal-content__buttons
button.modal-content__button.modal-content__button--apply Применить
button.modal-content__button.modal-content__button--close Закрыть
+modal-content-popup('temperature')
来源:https://stackoverflow.com/questions/16579461/jade-doesnt-let-me-use-include-variable-in-a-mixin