We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10779
    • 22 Posts
    Does anyone have a list of, or now how to use placeholders for ajaxSearch?

    In the pagination I would like to know which page I am on
    how many pages there are
    What the link to the next page is if there is one, and
    What the link to the previous page is if there is one..

    Any help would be greatly appreciated

    Nicholas
      • 5811
      • 1,717 Posts
      In the pagination I would like to know which page I am on
      how many pages there are
      What the link to the next page is if there is one, and
      What the link to the previous page is if there is one.
      These placeholders don’t exist with the release 1.8.1

      If you would like these placeholders change the file snippets/ajaxSearch/classes/ajaxSearch.class.inc.php by adding the following lines of code after the line #564:
            // set placeholders nbPages, currentPage, previousPage, previousPageLink, nextPage, nextPageLink
            $varPaging['nbPages'] = $numResultPages;
            $currentPage = ceil($this->offset/$grabMax)+1;
            $varPaging['currentPage'] = $currentPage;
            $previousPage = $currentPage - 1;
            $nextPage = $currentPage + 1;
            if ($previousPage > 0){        
              $varPaging['previousPage'] = $previousPage;
              $previousOffset = $this->offset - $grabMax;
              if (!isset($this->subSearch)) $varPaging['previousPageLink'] = $modx->makeUrl($modx->documentIdentifier,'','AS_offset='.$previousOffset.'&AS_search='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch));
              else $varPaging['previousPageLink'] = $modx->makeUrl($modx->documentIdentifier,'','AS_offset='.$previousOffset.'&AS_search='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch).'&subsearch='.urlencode($this->subSearch));
            }
            else $varPaging['previousPageLink'] = '';     
      
            if ($nextPage <= $numResultPages){        
              $varPaging['nextPage'] = $nextPage;
              $nextOffset = $this->offset + $grabMax;
              if (!isset($this->subSearch)) $varPaging['nextPageLink'] = $modx->makeUrl($modx->documentIdentifier,'','AS_offset='.$nextOffset.'&AS_search='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch));
              else $varPaging['nextPageLink'] = $modx->makeUrl($modx->documentIdentifier,'','AS_offset='.$nextOffset.'&AS_search='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch).'&subsearch='.urlencode($this->subSearch));
            }
            else $varPaging['nextPageLink'] = '';
            
      
      Then the placeholders [+as.nbPages+], [+as.currentPage+], [+as.previousPage+], [+as.previousPageLink+], [+as.nextPage+], +as.nextPageLink+] could be used in the template templates/paging.tpl.html.
      If the previousPage is <1 then previousPageLink=`` and if the nextPage>nbPages then nextPageLink=``, so before to used these 2 Placeholders check these values.
      For instance you could adapt the paging.tpl.html template like that:
      [+as.tpl:is=`paging`:then=`
        <span class="ajaxSearch_paging">
          Number of pages: [+as.nbPages+]<br />
          [+as.previousPageLink:isnot=``:then=`
          Previous page: <a href="[+as.previousPageLink+]">[+as.previousPage+]</a><br />
          `+]
          Current page: [+as.currentPage+]<br />
          [+as.nextPageLink:isnot=``:then=`
          Next page: <a href="[+as.nextPageLink+]">[+as.nextPage+]</a><br />
          `+]
          <br />
          [+as.pagingText+]
          [+as.pagingLinks+]
        </span>
      `+]
      [+as.tpl:is=`pagingLinks`:then=`
        <a href="[+as.pagingLink+]">[+as.pagingText+]</a>[+as.pagingSeparator+]
      `+]
      [+as.tpl:is=`pagingLinksCurrent`:then=`
        [+as.pagingText+][+as.pagingSeparator+]
      `+]
      Find enclosed the updated file classes/ajaxSearch.class.inc.php. To use it simply drop it in the folder ajaxSearch/classes
        • 10779
        • 22 Posts
        Wow.. thanks for this.
        Appreciate it!