Thank you very much! On Monday, July 21, 2014 at 11:19:46 PM UTC+4, Jason Hutchinson wrote: > > I put together a really simple pager here: > http://play.golang.org/p/rM2cw-g2u7 > > It implements one of my favorite pagination formats, which always shows > the first and last pages, current pages, and at least N pages to either > side of current. > > I think this could be fairly easily adapted to output an HTML template. > > On Saturday, July 19, 2014 3:00:12 AM UTC-5, Nikita Loskutov wrote: >> >> Hello! I need to implement pagination. Actually I have "pages" array, >> "page" param and "per_page" variable. >> In my code: >> >> pages_count := math.Floor(float64(len(pages)) / float64(per_page)) >> >> then in template I need something like (pseudocode): >> >> {{ if .page - 2 > 0 }} >> {{ $start_page := .page - 2 }} >> {{ else }} >> {{ $start_page := 1 }} >> {{ end }} >> >> {{ if .page + 2 >= .pages_count }} >> {{ $finish_page := .page + 2 }} >> {{ else }} >> {{ $finish_page := .pages_count }} >> {{ end }} >> >> <ul> >> {{ for $i := $start_page; $i <= $finish_page; ++$i }} >> <li {{ if $i == .page }} class="current_page" {{ end }}> >> <a href="{{ url "Pages.Show" .$i }}">$i</a> >> </li> >> {{ end }} >> </ul> >> >> How to implement this correctly? >> Thx >> >
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.