Jade / Pug:变量没有在mixin中显示

时间:2016-07-07 19:34:42

标签: express pug

我是Jade / Pug的新手,当我没有在变量中添加变量代码时,它可以正常工作,但是当我使用mixin时,没有任何东西显示变量。我希望有人可以解释我如何正确使用变量中的mixins。

//-works
.teacher-wrapper
  .teacher-container
    each student in students
      .studentCardContainer.shadow90
        .studentInfoContainer
          .studentPhotoContainer
            .studentPhoto
              img(src="some_img.jpg")
            .studentName= student //<------ works
        .studentEmotionContainer
          div text
          div text

在这个例子中,我想为每个学生使用mixin,但= student不起作用。我也试过#{student},但它没有用。

//- doesn't work
 .teacher-container
    each student in students
      +studentCard

    mixin studentCard
      .studentCardContainer.shadow90
        .studentInfoContainer
          .studentPhotoContainer
            .studentPhoto
              img(src="some_img.jpg")
            .studentName= student//<------ doesn't work ?
        .studentEmotionContainer
          div text
          div text

1 个答案:

答案 0 :(得分:1)

您需要将student设置为mixin的参数:

mixin studentCard(student)
  .studentCardContainer.shadow90
    .studentInfoContainer
      .studentPhotoContainer
        .studentPhoto
          img(src="some_img.jpg")
        .studentName= student
    .studentEmotionContainer
      div text
      div text

.teacher-container
  each student in students
    +studentCard(student)