Render pages pagination

pull/1/head
Nikita Tokarchuk 2 years ago
parent b0d49ffe3b
commit 9b43855d07
Signed by: mainnika
GPG Key ID: A595FB7E3E56911C
  1. 46
      frontend/templates/blog.go.tmpl
  2. 9
      frontend/templates/funcs.go
  3. 14
      frontend/templates/index.go.tmpl

@ -13,6 +13,29 @@
{{ template "menu.go.tmpl" . }}
</div>
<!-- render top pagination -->
{{ if (gt .Pagination.Page 1) }}
<div class="pagination-container-top">
<ul>
{{ if (gt .Pagination.Page 1) }}
<li>
<a href="{{ getBlogURL }}?page={{ sub .Pagination.Page }}">{{ sub .Pagination.Page }}</a>
</li>
{{ end }}
<li>
{{ .Pagination.Page }} ←
</li>
{{ if (lt .Pagination.Page .Pagination.Total) }}
<li>
<a href="{{ getBlogURL }}?page={{ add .Pagination.Page }}">{{ add .Pagination.Page }}</a>
</li>
{{ end }}
</ul>
</div>
{{ end }}
<!-- render posts -->
<div class="posts-container">
{{ range .Posts }}
@ -20,6 +43,29 @@
{{ end }}
</div>
<!-- render bottom pagination -->
{{ if (gt .Pagination.Total 1) }}
<div class="pagination-container-bottom">
<ul>
{{ if (gt .Pagination.Page 1) }}
<li>
<a href="{{ getBlogURL }}?page={{ sub .Pagination.Page }}">{{ sub .Pagination.Page }}</a>
</li>
{{ end }}
<li>
{{ .Pagination.Page }} ←
</li>
{{ if (lt .Pagination.Page .Pagination.Total) }}
<li>
<a href="{{ getBlogURL }}?page={{ add .Pagination.Page }}">{{ add .Pagination.Page }}</a>
</li>
{{ end }}
</ul>
</div>
{{ end }}
</section>
</body>

@ -4,8 +4,17 @@ import "html/template"
func UseFuncs() template.FuncMap {
return template.FuncMap{
"add": func(i int) int {
return i + 1
},
"sub": func(i int) int {
return i - 1
},
"getIndexURL": func() string {
return URLIndex
},
"getBlogURL": func() string {
return URLBlog
},
}
}

@ -33,6 +33,20 @@
{{ end }}
</div>
<!-- render bottom pagination -->
{{ if (gt .Pagination.Total 1) }}
<div class="pagination-container-bottom">
<ul>
<li>
{{ .Pagination.Page }} ←
</li>
<li>
<a href="{{ getBlogURL }}?page={{ add .Pagination.Page }}">{{ add .Pagination.Page }}</a>
</li>
</ul>
</div>
{{ end }}
</section>
</body>

Loading…
Cancel
Save