Improve this page on GitHub


We use often pagination in templates. How do we do that?
We have created this demo for pagination. We hope it’s useful to you.


Before you can use the paginator in the view you have to set it in your controller:

package controllers

type PostsController struct {

func (this *PostsController) ListAllPosts() {
    // sets this.Data["paginator"] with the current offset (from the url query param)
    postsPerPage := 20
    paginator := pagination.SetPaginator(this, postsPerPage, CountPosts())

    // fetch the next 20 posts
    this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage)


Example templates (using Twitter Bootstrap):

comments powered by Disqus