简体   繁体   English

如何在JADE中自定义此混合

[英]How to Customize this mixin in JADE

I'm working on a mixin in Jade which creates divs with img tags... here is the mixin code: 我正在使用Jade中的mixin来创建带有img标签的div ...这是mixin代码:

mixin image(pics)
  each pic in pics
    .row
      .col-md-4
        img.img-responsive(src="#{pic.path}" alt="#{pic.name}")

and here is an example when I use the mixin: 这是我使用mixin的示例:

+image([
    {'name':'anti'    , 'path':'/images/anti.jpg'},
    {'name':'dark'    , 'path':'/images/dark.jpg'},
    {'name':'haik'    , 'path':'/images/haik.jpg'},
    {'name':'james'   , 'path':'/images/james.jpg'},
    {'name':'johanna' , 'path':'/images/johanna.jpg'},
    {'name':'timothy' , 'path':'/images/Timothy.jpg'}
    ])

Is it possible to assign all this values to a variable in other file then includes the file and use the mixin? 是否可以将所有这些值分配给其他文件中的变量,然后包括该文件并使用mixin? if yes, how? 如果是,如何? :D :D

this is the goal, I just demonstrate what I mean, obviously the code below wont work: 这是目标,我只是证明我的意思,显然下面的代码行不通:

var allPics = [
        {'name':'anti'    , 'path':'/images/anti.jpg'},
        {'name':'dark'    , 'path':'/images/dark.jpg'},
        {'name':'haik'    , 'path':'/images/haik.jpg'},
        {'name':'james'   , 'path':'/images/james.jpg'},
        {'name':'johanna' , 'path':'/images/johanna.jpg'},
        {'name':'timothy' , 'path':'/images/Timothy.jpg'}
        ]

+image(allPics)

Yes, you can use variables in an included file as well as Mixins . 是的,您可以在包含的文件和Mixins使用变量。

test.jade includes test_include.jade test.jade包括test_include.jade

test_include.jade: test_include.jade:

- var allPics  = [{'name':'anti'    , 'path':'/images/anti.jpg'},{'name':'dark'    , 'path':'/images/dark.jpg'},{'name':'haik'    , 'path':'/images/haik.jpg'},{'name':'james'   , 'path':'/images/james.jpg'},{'name':'johanna' , 'path':'/images/johanna.jpg'},{'name':'timothy' , 'path':'/images/Timothy.jpg'}]
mixin image(pics)
  each pic in pics
    .row
      .col-md-4
        img.img-responsive(src="#{pic.path}" alt="#{pic.name}")
block content

test.jade: test.jade:

extends test_include
  block content
   +image(allPics)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM