Skip to content

Commit

Permalink
Find first image using handlebars
Browse files Browse the repository at this point in the history
When I first wrote this I didn't know how to index an array in
handlebars. Now I do!

This is better to have in handlebars because it's simpler and the JS
doesn't need to care that an image is being displayed.
  • Loading branch information
John Hawthorn committed Mar 9, 2017
1 parent 2a4b3fd commit 10508c1
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</td>
{{else}}
<td class="line-item-image">
{{> _image image=image size="mini" }}
{{> _image image=line_item.variant.images.[0] size="mini" }}
</td>
<td class="line-item-name">
{{ line_item.variant.name }}<br>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="variant-autocomplete-item media">
<div class="media-left">
{{> _image image=image size="mini" }}
{{> _image image=variant.images.[0] size="mini" }}
</div>

<div class="media-body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
variantTemplate = HandlebarsTemplates["variants/autocomplete"]

formatVariantResult = (variant) ->
image = variant.images[0]
variantTemplate(
variant: variant
image: image
)

$.fn.variantAutocomplete = (searchOptions = {}) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ Spree.Views.Cart.LineItemRow = Backbone.View.extend({
},

render: function() {
var line_item = this.model.attributes
var image = line_item.variant && line_item.variant.images[0]
var html = HandlebarsTemplates['orders/line_item']({
line_item: line_item,
image: image,
line_item: this.model.toJSON(),
editing: this.editing,
isNew: this.model.isNew(),
noCancel: this.model.isNew() && this.model.collection.length == 1
Expand Down

0 comments on commit 10508c1

Please sign in to comment.