In my gulpfile I'm defining a memberInfo array of objects to pass to the template:
var gulp = require('gulp');
var handlebars = require('gulp-compile-handlebars');
var rename = require('gulp-rename');
var handlebars_helpers = require('handlebars-helpers')();
//http://assemble.io/helpers/helpers-html.html
var _ = require('underscore');
gulp.task('default', function () {
var templateData = {
memberInfo: [
{"member_email": "amy@email.com", "list_id": "2", "name": "obsession cologne 3 oz", "brand": "", "price": "55.99"},
{"member_email": "amy@email.com", "list_id": "1", "name": "red plaid skirt", "brand": "versace", "price": "55.99"},
{"member_email": "amy@email.com", "list_id": "1", "name": "black ruffle shirt", "brand": "versace", "price": "47.99"},
]
}
options = {
helpers: _.extend(handlebars_helpers)
}
return gulp.src('template/email.handlebars')
.pipe(handlebars(templateData, options))
.pipe(rename('email.html'))
.pipe(gulp.dest('output'));
}
What I want to do on my template is say "for each object in memberInfo, if the list_id is equal to 1, display these fields"
{{name}}
{{brand}}
{{price}}
What is the proper way of doing this? I'm brand new to gulp and handlebars and the explanations I've found don't seem to make any sense in this context. Handlebar-helpers has a nifty comparison operator {{#is }}
so I wrote this code, but it obviously isn't set up properly:
<ul>
{{#each memberInfo}}
{{#each this}}
<li>Key: {{@key}} Value = {{this}}</li>
{{#is @key 'list_id' }}
{{#is this 1 }}
{{name}}
{{brand}}
{{price}}
//Nothing is accessible here except this, as far as i can tell, so none of these values render
{{/is}}
{{/is}}
{{/each}}
{{/each}}
</ul>