[英]Jade: how can I pass a random variable into included template?
我有一个翡翠模板(“主页”)和一个可重复使用的模板(“产品模板”)。 “产品模板”必须显示动态数据,其他许多页面也使用了它,因此它必须统一且不依赖变量名。
// main page
... (some code) ...
- var outerObj = [
{ title: '...', price: '...', description: '' },
{ title: '...', price: '...', description: '' },
{ title: '...', price: '...', description: '' }
];
// product temptate
.product
.product__title=outerObj.title
.product__price=outerObj.price
.product__description=outerObj.description
如何在循环中包含“产品模板”并传递参数? (有点像)
// example of regular usage of 'product template':
- for (var i = 0; i < outerObj.length; i++)
// pass only outerObj[i]
include ./path/to/product-template.jade'
与其在循环内进行include
不如使用像函数一样的mixin 。
像这样:
mixin makeProduct(product)
.product
.product__title=product.title
.product__price=product.price
.product__description=product.description
each product in outerObj
+makeProduct(product)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.