0

I have a very long list of titles in my data file data/works.yml which looks more or less like this:

--- 
- 
  id: 947
  title: "First"
- 
  id: 955
  title: "Second"

The list is too long too display without pagination. How can I paginate index.html, where I want this list to be displayed?

helcim
  • 789
  • 13
  • 27

1 Answers1

1

It turned out to be much easier than I thought. It was only a matter of adding gem 'middleman-pagination' in Gemfile, in config.rb:

activate :pagination do
  pageable_set :works do
   data.works
  end
end

and in index.html.erb

---
pagination:
  for: works
  per_page: 20
---
      <ol>
      <% pagination.each do |w| %>
                <li>
                        <%= w.title %>
                </li>
      <% end %>

      <%= link_to "Next page", pagination.next_page.url if pagination.next_page %>

As explained here: https://github.com/Aupajo/middleman-pagination

helcim
  • 789
  • 13
  • 27