Skip to content

Instantly share code, notes, and snippets.

@benhowdle89
Created May 22, 2013 14:55
Show Gist options
  • Save benhowdle89/5628170 to your computer and use it in GitHub Desktop.
Save benhowdle89/5628170 to your computer and use it in GitHub Desktop.
var model.LineItems = [blah, blah, blah]; // pseudo array declaration
var projects = BB.Collection; // pseudo collection declaration
model.LineItems[1].ProjectNumber = 'xyz'; // an example value for a line item
//in view render function
for (x in model.LineItems) {
model.LineItems[x].projects = projects;
}
//html in template
<select id="quotesProject">
{{#select model.ProjectNumber}}
{{#each projects}}
<option value="{{Number}}">{{Name}}</option>
{{/each}}
{{/select}}
</select>
@jackfranklin
Copy link

So you have a collection of models, each of which share the same projects collection?

In this case I'd be tempted to extract this into a separate template:

{{#each projects}}
        <option value="{{Number}}">{{Name}}</option>
{{/each}}

And only render it once, with the projects collection, and then drop it into the model template.

Maybe?

@benhowdle89
Copy link
Author

@jackfranklin: Can you nest templates in Handlebars?

@benhowdle89
Copy link
Author

@jackfranklin: You can in Meteor and it's such a dream!

@jackfranklin
Copy link

You could render one and dump it inside another.

If you use {{{ foo }}} in Handlebars it will dump text out and not escape it.

@jackfranklin
Copy link

Doing it that way does at least mean:

  • not rendering the same projects for every single model
  • no need to do the extra work adding the property to the model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment