Bug #23486 See Comments

Custom Module Pagination Doesn’t Parse Tags

Version: 4.0.9 Reporter: anthony.pinskey

I am writing a custom module that does some unique fitlering and queries. I’d like to paginate the results across several pages. I am using the pagination library but there seems to be some issues.

I am not 100% sure if this is a bug or lack of documentation causing the confusion as stuff seems a bit scattered on the subject.

Following the directions this is what I end up with:

// Pagination Settings
  ee()->load->library('pagination');
  // Create the pagination object
  $pagination = ee()->pagination->create();
  // Per page limit
  $per_page = 10;
  // This ensures page 1 starts at 0
  $start = $per_page * ($page - 1);

  // Query the model
  
  // Build tags
  $variables[] = [
    // Various data gets set here for the tag pairs
  ];
  
  $total_items = $products->count();
  $per_page = ee()->TMPL->fetch_param('limit');
  $pagination->position = 'bottom';

  ee()->TMPL->tagdata = $pagination->prepare(ee()->TMPL->tagdata);

  $pagination->build($total_items, $per_page);

  $pagination->render($variables);

  return ee()->TMPL->parse_variables(ee()->TMPL->tagdata, $variables);

However, on the tag, the pagination links never show

{exp:module:results}
  {paginate}
      Page {current_page} of {total_pages} pages {pagination_links}
  {/paginate}
{/exp:moduleresults}

If I dump the $pagination object however, it does show a correcctly formated object.

object(Pagination_object)#387 (22) { ["paginate"]=> bool(true) ["total_items"]=> int(10) ["total_pages"]=> int(1) ["per_page"]=> string(2) "10" ["offset"]=> int(0) ["current_page"]=> float(1) ["basepath"]=> string(29) "http://ee4.qa/results" ["prefix"]=> string(1) "P" ["cfields"]=> array(0) { } ["field_pagination"]=> bool(false) ["field_pagination_query"]=> NULL ["_template_data":"Pagination_object":private]=> array(1) { ["b4974dda97a760fb6f75a8a4353a122c"]=> string(78) "
Page {current_page} of {total_pages} pages {pagination_links}

" } ["_page_array":"Pagination_object":private]=> array(0) { } ["_multi_fields":"Pagination_object":private]=> string(0) "" ["_page_next":"Pagination_object":private]=> string(0) "" ["_page_previous":"Pagination_object":private]=> string(0) "" ["_page_links":"Pagination_object":private]=> string(0) "" ["_page_links_limit":"Pagination_object":private]=> int(2) ["_type":"Pagination_object":private]=> string(42) "Module\Example" ["_position":"Pagination_object":private]=> string(6) "bottom" ["_pagination_marker":"Pagination_object":private]=> string(17) "pagination_marker" ["_always_show_first_last":"Pagination_object":private]=> bool(false) }

But it doesn’t seem to set the paginate key onto the variables array.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases