defmodule FlopPhoenix do @moduledoc """ View helper functions for Phoenix and Flop. ## Pagination `Flop.meta/3` returns a `Flop.Meta` struct, which holds information such as the total item count, the total page count, the current page etc. This is all you need to render pagination links. `Flop.run/3`, `Flop.validate_and_run/3` and `Flop.validate_and_run!/3` all return the query results alongside the meta information. If you set up your context as described in the [Flop documentation](https://hexdocs.pm/flop), you will have a `list` function similar to the following: @spec list_pets(Flop.t() | map) :: {:ok, {[Pet.t()], Flop.Meta.t}} | {:error, Changeset.t()} def list_pets(flop \\ %{}) do Flop.validate_and_run(Pet, flop, for: Pet) end ### Controller You can call this function from your controller to get both the data and the meta data and pass both to your template. defmodule MyAppWeb.PetController do use MyAppWeb, :controller alias Flop alias MyApp.Pets alias MyApp.Pets.Pet action_fallback MyAppWeb.FallbackController def index(conn, params) do with {:ok, {pets, meta}} <- Pets.list_pets(params) do render(conn, "index.html", meta: meta, pets: pets) end end end ### View To make the `FlopPhoenix` functions available in all templates, locate the `view_helpers/0` macro and add another import statement: defp view_helpers do quote do # ... import FlopPhoenix # ... end end ### Template In your index template, you can now add pagination links like this: