简体   繁体   中英

Setting pagination in nestacms

I'm using nestacms for a new website.

I'm trying to add pagination where i'm listing articles.

There's no documentation on the official website.

I've tried with following gems :

  • will_paginate
  • kaminary

But I don't get it.

Do somone knows how to add pagination on nestacms ?

Thanks.

Well, it is quite complicated. As far as you don't have write access to Nesta controllers and Nesta doesn't use any database, you cannot use pagination gems.

As quick-and-dirty solution I made some changes in /views/summaries.haml

- unless pages.empty?
  - per_page = 10
  - page = params[:page].nil? ? 1 : params[:page].to_i
  - start_page = (page - 1) * per_page
  - end_page = page * per_page - 1

  - all_pages = Nesta::Page.find_articles
  - pages = all_pages[start_page..end_page]
  %ol

... unchanged code here

        = haml :page_meta, :layout => false, :locals => { :page => page }

  -if page*per_page < all_pages.size
    %a.perv{href:"/?page=#{page+1}"} Previous page
  -if page > 1
    %a.next{href:"/?page=#{page-1}"} Next page

Then you could adjust your .prev and .next classes as you like with CSS

As very proper solution I would suggest to make a pull request to Nesta repository with any pagination gem support by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM