How you call the getPage in the snippet?

Hello, I have snippet with parameters and inside I try to call the getPage but the pagination is not display.

*Btw when I write in the search bar the link with page number for example /decisions.html?page=3 is working.

This is my snippet:

<?php
$params = array(
  'elementClass' => 'modSnippet',
  'element' => 'paging_snippet',
  'tpl' => $tpl,
  'pageVarKey' => 'page',
  'totalVar' => 'total',
  'limit' => '20',
  'offset' => '0',
  'pageLimit' => '2',
  'c2g_paging_id' => $c2g_resourceId,
  'table' => $table,
  'cultureKey' => $cultureKey
);
$output = $modx->runSnippet('getPage',$params);
if(empty($output)){
    $output_empty = '<h3>'.$modx->runSnippet('get_translation', array('text' => 'no_results')).'</h3>';
    return $output_empty;
}
$output .= '<div class="pageNav w-100 d-flex justify-content-center mt-5">[[!+page.nav]]</div>';
echo $output;

What exactly is not working?

If you can’t see the navigation [[!+page.nav]], then maybe you have to read the placeholder in the code and replace

$output .= '<div class="pageNav w-100 d-flex justify-content-center mt-5">[[!+page.nav]]</div>';

with

$page_nav = $modx->getPlaceholder('page.nav');
$output .= '<div class="pageNav w-100 d-flex justify-content-center mt-5">' . $page_nav . '</div>';

I still not working. The pagination is empty.

Capture

What is paging_snippet? Does this snippet set a placeholder for the total amount of results?

Does it work if you use getResources instead:

$params = array(
  'elementClass' => 'modSnippet',
  'element' => 'getResources',
  'tpl' => $tpl,
  'limit' => '20',
  'offset' => '0',
  'pageLimit' => '2'
);

Yes in the snippet is set a placeholder for the total amount. This is the paging_snippet

$add_to_where = '';
$sort = '';
$table ='modx_decisions_posts';
$sort = $_GET["sort_type_value"];

$sql = "SELECT id FROM $table WHERE published='1'";
$query = $modx->query($sql);

$total = count($query->fetchAll(PDO::FETCH_ASSOC));
$_SESSION['totalVar'] = $total;
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');

$modx->setPlaceholder($totalVar,$total);

$limit = $modx->getOption('limit',$scriptProperties,20);
$_SESSION['limit'] = $limit;
$offset = $modx->getOption('offset',$scriptProperties,0);

if ($sort == 'DESC') {
    $sql = "SELECT * FROM $table WHERE published='1' ORDER BY date DESC LIMIT ".$limit." OFFSET ".$offset."";

    $query = $modx->query($sql);
    $collection = $query->fetchAll(PDO::FETCH_ASSOC);
    
    $out = array();
    foreach($collection as $item) {
        $out[] = $modx->getChunk($tpl, $item);
    }
// Run this
} elseif ( $sort == 'ASC' ) {
// Run this
    $sql = "SELECT * FROM $table WHERE published='1' ORDER BY date ASC LIMIT ".$limit." OFFSET ".$offset."";
    
    $query = $modx->query($sql);
    $collection = $query->fetchAll(PDO::FETCH_ASSOC);
    
    $out = array();
    foreach($collection as $item) {
        $out[] = $modx->getChunk($tpl, $item);
    }
} else {
    $sql = "SELECT * FROM $table WHERE published='1' ORDER BY date DESC LIMIT ".$limit." OFFSET ".$offset."";
    
    $query = $modx->query($sql);
    $collection = $query->fetchAll(PDO::FETCH_ASSOC);
    
    $out = array();
    foreach($collection as $item) {
        $out[] = $modx->getChunk($tpl, $item);
    }
}

return implode("\n", $out);
`

you could just try to use rowboat, or if you would have a proper xpdo-package migxLoopCollection

This code looks ok. I can’t identify the problem.

You probably have to do some debugging.
Here is where the page navigation is generated (function getpage_buildControls):

You could output a log message to see what the values are and if the condition is met.

$modx->log(modX::LOG_LEVEL_ERROR,'total='.$properties[$properties['totalVar']].'|limit='.$properties['actualLimit'].'|page='.$properties['page'].'|pageOneLimit='.$properties['pageOneLimit']);

@bruno17 I need this snippet because the code is extended for multi-filter search and I can not change something.