Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for product sections #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ copyright = "| Copyright © 2019 [Gethugothemes](https://gethugothemes.com)
# Snipcart Credentials
snipcartApiKey = "M2E5YjA3NjMtYzRiYS00YzVjLWEyYWYtNDY5ZDI0OWZhYjg5"
currencySymbol = "$"
# whether to show product sections among products
showProductSections = true

# Preloader
[params.preloader]
Expand Down
18 changes: 14 additions & 4 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,21 @@ <h2>{{ .title | markdownify }}</h2>
{{ end }}
</div>
{{ range first 6 (where site.RegularPages "Type" "products") }}
{{ if not .IsSection }}
{{ $image := "" }}
{{ if .Params.Image }}
{{ $image = .Params.Image | absURL }}
{{ else }}
{{ if .Params.Images }}
{{ range first 1 .Params.Images }}
{{ $image = .image | absURL }}
{{ end }}
{{ end }}
{{ end }}
<div class="col-lg-4 col-sm-6 mb-4">
<div class="card border-0 text-center">
<a href="{{ .Permalink }}">
{{ range first 1 .Params.Images }}
<img src="{{ .image | absURL }}" alt="{{ .Title }}" class="card-img-top">
{{ end }}
<img src="{{ $image }}" alt="{{ .Title }}" class="card-img-top">
</a>
<div class="card-body">
<a href="{{ .Permalink }}" class="h4">{{ .Title }}</a>
Expand All @@ -184,14 +193,15 @@ <h2>{{ .title | markdownify }}</h2>
<span class="lead text-primary">{{ site.Params.currencySymbol }}{{ .Params.Price }}</span>
</div>
<button class="snipcart-add-item btn btn-sm btn-outline-primary" data-item-id="{{ .Params.ProductID }}"
data-item-name="{{ .Title }}" {{ range first 1 .Params.Images }} data-item-image="{{ .image | absURL }}"
data-item-name="{{ .Title }}" {{ range first 1 .Params.Images }} data-item-image="{{ $image }}"
{{ end }} data-item-price="{{ .Params.Price }}" data-item-url="{{ .Permalink }}" data-item-description="{{ .Description }}">
Add to cart
</button>
</div>
</div>
</div>
{{ end }}
{{ end }}
</div>
</div>
</section>
Expand Down
22 changes: 17 additions & 5 deletions layouts/products/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,43 @@
<div class="container">
<div class="row">
{{ range .Data.Pages }}
{{ if site.Params.showProductSections | or (not .IsSection) }}
{{ $image := "" }}
{{ if .Params.Image }}
{{ $image = .Params.Image | absURL }}
{{ else }}
{{ if .Params.Images }}
{{ range first 1 .Params.Images }}
{{ $image = .image | absURL }}
{{ end }}
{{ end }}
{{ end }}
<div class="col-lg-4 col-sm-6 mb-4">
<div class="card border-0 text-center">
<a href="{{ .Permalink }}">
{{ range first 1 .Params.Images }}
<img src="{{ .image | absURL }}" alt="{{ .Title }}" class="card-img-top">
{{ end }}
<img src="{{ $image }}" alt="{{ .Title }}" class="card-img-top">
</a>
<div class="card-body">
<a href="{{ .Permalink }}" class="h4">{{ .Title }}</a>
<p>{{ .Params.Description }}</p>
{{ if .Params.Price }}
<div class="mb-4">
{{ if .Params.PriceBefore }}
<s>{{ site.Params.currencySymbol }}{{ .Params.PriceBefore }}</s>
{{ end }}
<span class="lead text-primary">{{ site.Params.currencySymbol }}{{ .Params.Price }}</span>
</div>
<button class="snipcart-add-item btn btn-sm btn-outline-primary" data-item-id="{{ .Params.ProductID }}"
data-item-name="{{ .Title }}" {{ range first 1 .Params.Images }} data-item-image="{{ .image | absURL }}"
{{ end }} data-item-price="{{ .Params.Price }}" data-item-url="{{ .Permalink }}" data-item-description="{{ .Description }}">
data-item-name="{{ .Title }}" data-item-image="{{ $image }}"
data-item-price="{{ .Params.Price }}" data-item-url="{{ .Permalink }}" data-item-description="{{ .Description }}">
Add to cart
</button>
{{ end }}
</div>
</div>
</div>
{{ end }}
{{ end }}
</div>
</div>
</section>
Expand Down
11 changes: 10 additions & 1 deletion layouts/products/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
<section class="section pt-0">
<div class="container">
<div class="row">
{{ $image := "" }}
{{ if .Params.Image }}
{{ $image = .Params.Image | absURL }}
{{ else }}
{{ range first 1 .Params.Images }}
{{ $image = .image | absURL }}
{{ end }}
{{ end }}

<div class="col-lg-5 mb-4 mb-lg-0">
<!-- product image slider -->
<div class="product-slider">
Expand All @@ -30,7 +39,7 @@ <h4 class="font-weight-medium">{{ .Title }}</h4>
<h5>Short Description</h5>
<p>{{ .Params.ShortDescription | markdownify }}</p>
<button class="snipcart-add-item btn btn-primary" data-item-id="{{ .Params.ProductID }}"
data-item-name="{{ .Title }}" {{ range first 1 .Params.Images }} data-item-image="{{ .image | absURL }}"
data-item-name="{{ .Title }}" {{ range first 1 .Params.Images }} data-item-image="{{ $image }}"
{{ end }} data-item-price="{{ .Params.Price }}" data-item-url="{{ .Permalink }}" data-item-description="{{ .Description }}">
Add to cart
</button>
Expand Down