return function () {
    $self = url('/@object/@action/' . urlencode('html/pagination'));
    $pager = _class('docs')->_sample('pagination');
    $rows = _class('docs')->_sample('products')->load();
    $p = $pager->params($_GET, count($rows));
    $query = $pager->query($p);
    // the pager appends &page=N; the demo id holds a slash, so the base url is given (the default ./?object=&action=&id= would not do)
    $url_path = $self . '?' . $query;

    $intro = '<p class="docs-demo-intro">The framework pager: <code>common()->divide_pages()</code> takes an SQL query, a query builder or
        an array and returns the rows (or the <code>LIMIT</code>) of the current page with the page links; <code>table2</code> pages with it
        too (<code>pager_records_on_page</code>, see the <a href="' . url('/@object/@action/' . urlencode('table/products')) . '">table demo</a>).
        Here it pages the ' . count($rows) . ' sample products in memory. <b>slide</b> keeps the current page in the middle of the
        visible numbers, <b>blocks</b> shows fixed blocks with jumps to the previous / next block. The options come from fixed lists
        and the page number is clamped, so <code>?page=999</code> shows the last page; the links work without JavaScript.
        Classes: <code>yf_divide_pages</code>, <code>yf_common</code>, <code>yf_html</code> (<code>pagination()</code>).</p>';

    $options = function ($name, array $values, $selected, $label) {
        $html = '<label>' . $label . ' <select name="' . $name . '" class="form-control form-select input-sm form-select-sm">';
        foreach ($values as $value => $text) {
            $html .= '<option value="' . _prepare_html((string) $value, 0) . '"' . ((string) $value === (string) $selected ? ' selected' : '') . '>' . _prepare_html((string) $text, 0) . '</option>';
        }
        return $html . '</select></label>';
    };
    $form = '<form method="get" action="' . $self . '" class="docs-demo-pager-form">'
        . $options('per_page', array_combine($pager->PER_PAGE, $pager->PER_PAGE), $p['per_page'], 'Per page')
        . $options('type', $pager->TYPES, $p['type'], 'Type')
        . $options('block', array_combine($pager->BLOCKS, $pager->BLOCKS), $p['block'], 'Pages per block')
        . $options('size', $pager->SIZES, $p['size'], 'Size')
        . $options('align', $pager->ALIGNS, $p['align'], 'Align')
        . '<button type="submit" class="btn btn-primary btn-sm">Apply</button>'
        . '<a class="btn btn-default btn-outline-secondary btn-sm" href="' . $self . '">Reset</a></form>';

    [$items, $pages_html, $total, $first, $total_pages] = $pager->divide($rows, $p, $url_path);
    $trs = '';
    $n = $first;
    foreach ((array) $items as $row) {
        $trs .= '<tr><td>' . (++$n) . '</td><td>' . _prepare_html((string) $row['name'], 0) . '</td><td>' . _prepare_html((string) $row['colour'], 0) . '</td>'
            . '<td class="text-right text-end">' . _prepare_html((string) $row['price'], 0) . '</td></tr>';
    }
    $last = min($total, $first + $p['per_page']);
    $table = '<div class="table-responsive"><table class="table table-condensed table-sm table-striped docs-demo-pager-rows"><thead><tr><th>#</th><th>Name</th><th>Colour</th><th class="text-right text-end">Price</th></tr></thead>'
        . '<tbody>' . $trs . '</tbody></table></div>';
    $summary = '<p class="text-muted">Products ' . ($first + 1) . '–' . $last . ' of ' . (int) $total . ', page ' . $p['page'] . ' of ' . (int) $total_pages . '</p>';

    [$data, $extra] = $pager->widget($p, (int) $total_pages, $url_path);
    $widget = '<h4>The bare widget: html()->pagination()</h4>'
        . '<p>The same state drawn by <code>html()->pagination($links, $extra)</code>: you pass page => link pairs plus <code>prev</code> /
            <code>next</code>, and the options <code>current</code>, <code>disabled</code>, <code>size</code> and <code>align</code>; it computes nothing itself.
            Under <a href="' . htmlspecialchars(_class('docs')->_bs_switch_url('5'), ENT_QUOTES) . '">?bs=5</a> it renders Bootstrap 5 markup (<code>yf_html_bs5</code>),
            under <a href="' . htmlspecialchars(_class('docs')->_bs_switch_url('3'), ENT_QUOTES) . '">?bs=3</a> Bootstrap 3.</p>'
        . html()->pagination($data, $extra);

    css('.docs-demo-pager-form { display:flex; flex-wrap:wrap; align-items:flex-end; gap:8px 12px; margin-bottom:15px; }
        .docs-demo-pager-form label { font-weight:normal; margin:0; } .docs-demo-pager-form .form-control { display:inline-block; width:auto; }
        .cssfw-bs5 .docs-demo-pager-form select.form-select { padding-right:2rem; }
        .docs-demo-pager-rows { margin-bottom:5px; } pre.docs-demo-pager-code code { white-space:pre-wrap; }');
    return $intro . $form
        . '<h4>common()->divide_pages()</h4>' . $table . $summary . $pages_html
        . '<pre class="docs-demo-pager-code"><code class="php">' . _prepare_html($pager->code($p), 0) . '</code></pre>'
        . $widget;
};

The framework pager: common()->divide_pages() takes an SQL query, a query builder or an array and returns the rows (or the LIMIT) of the current page with the page links; table2 pages with it too (pager_records_on_page, see the table demo). Here it pages the 20 sample products in memory. slide keeps the current page in the middle of the visible numbers, blocks shows fixed blocks with jumps to the previous / next block. The options come from fixed lists and the page number is clamped, so ?page=999 shows the last page; the links work without JavaScript. Classes: yf_divide_pages, yf_common, yf_html (pagination()).

Reset

common()->divide_pages()

#NameColourPrice
13Winner T-shirt, greygrey35.00
14Hill T-shirt, whitewhite35.00
15Roseheart T-shirt, blackblack35.00

Products 13–15 of 20, page 5 of 7

[$items, $pages_html, $total, $first, $total_pages] = common()->divide_pages(
    $rows, $url, 'slide', 3, 0, '', 0,
    [
        'requested_page' => $page,
        'pages_per_block' => 5,
        'add_get_vars' => 0,
    ]
);

The bare widget: html()->pagination()

The same state drawn by html()->pagination($links, $extra): you pass page => link pairs plus prev / next, and the options current, disabled, size and align; it computes nothing itself. Under ?bs=5 it renders Bootstrap 5 markup (yf_html_bs5), under ?bs=3 Bootstrap 3.