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

元气小坏坏 提交于 2019-12-11 02:40:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!