reuse product on homepage and products page

Tom Rutgers committed Aug 18, 2018
commit 8d0f6dc9a53df095418bdc83ecc8ca9b2c1a6729
Showing 3 changed files with 20 additions and 39 deletions
source/partials/homepage/_products.slim +1 -20
@@ @@ -8,23 +8,4 @@ section.homepage-products.products
- data.products.sort {|a,b| b[1].date <=> a[1].date}.first(3).each do | product |
//to get the actual data:
- - product = product[1]
-
- //link to product by converting the title to a slug
- .product
- = link_to '/products/' + product.title.parameterize
- .product-image
- = image_tag product.image
- .product-content
- .title
- h3 = product.title
- .price
- p
- = product.price.currency || '€'
- |
- = product.price.amount
- .weight
- p
- = product.weight.amount
- |
- = product.weight.unit || 'kg'
+ = partial 'partials/products/product', locals: {product: product[1]}
\ No newline at end of file
source/partials/products/_product.slim +18 -0
@@ @@ -0,0 +1,18 @@
+ //link to product by converting the title to a slug
+ .product
+ = link_to '/products/' + product.title.parameterize + '/'
+ .product-image
+ = image_tag product.image
+ .product-content
+ .title
+ h3 = product.title
+ .price
+ p
+ = product.price.currency || '€'
+ |
+ = product.price.amount
+ .weight
+ p
+ = product.weight.amount
+ |
+ = product.weight.unit || 'kg'
source/products.html.slim +1 -19
@@ @@ -8,23 +8,5 @@ section.products
- data.products.sort {|a,b| b[1].date <=> a[1].date}.each do | product |
//to get the actual data:
- - product = product[1]
+ = partial 'partials/products/product', locals: {product: product[1]}
- //link to product by converting the title to a slug
- .product
- = link_to '/products/' + product.title.parameterize
- .product-image
- = image_tag product.image
- .product-content
- .title
- h3 = product.title
- .price
- p
- = product.price.currency || '€'
- |
- = product.price.amount
- .weight
- p
- = product.weight.amount
- |
- = product.weight.unit || 'kg'