Jump to main content Jump to doc navigation

GalleryItemPagination Snippet

The GalleryItemPagination snippet offers placeholders for a basic navigation (previous, next) when displaying a single Gallery Item with GalleryItem.


GalleryItemPagination uses the following properties:

Name Description default value
curItem The ID of the image currently on display. Can be overridden by an URL parameter. 1, or an url parameter
checkForRequestVar Wether or not to override curItem with the url parameter as specified in the getParam property 1
getParam URL parameter to use with checkForRequestVar galItem
album The ID or name of an album to use 1
checkForRequestAlbumVar Whether or not to override album with the url parameter as specified in the albumRequstVar property 1
albumRequestVar URL parameter to use with checkForRequestAlbumVar galAlbum


GalleryItemPagination sets placeholders for the current, previous, next, first and last item in an album. You can find the namespaces for that in the table below. You can use the same fields the GalleryItem placeholders, minus album and tags.

Name Description
galitem.cur.* placeholder namespace for current item of album
galitem.prev.* placeholder namespace for previous item of album
galitem.next.* placeholder namespace for next item of album
galitem.first.* placeholder namespace for first item of album
galitem.last.* placeholder namespace for last item of album


Below you can find some common placeholders for GalleryItemPagination that can be used in your tpl/resource.

Name Description
galitem.cur.id placeholder for current item ID of album
galitem.prev.id placeholder for previous item ID of album
galitem.next.id placeholder for next item ID of album
galitem.first.id placeholder for first item ID of album
galitem.last.id placeholder for last item ID of album
galitem.next.filename filename of the next item
galitem.cur.description description of the current item

GalleryItemPagination examples

Display a basic navigation for an GalleryItem item and use previous and next placeholders.

Create snippet 'GalleryItemPagination'

First of all you have to create the snippet. Name it 'GalleryItemPagination' and save it.

// First instantiate the Gallery package
$curItem = $modx->getOption('curItem',$scriptProperties,1);
if ($modx->getOption('checkForRequestVar',$scriptProperties,true)) {
    $getParam = $modx->getOption('getParam',$scriptProperties,'galItem');
    if (!empty($_REQUEST[$getParam])) { $curItem = (int)$_REQUEST[$getParam]; }
if (empty($curItem)) return '';
$album = $modx->getOption('album',$scriptProperties,1);
if ($modx->getOption('checkForRequestAlbumVar',$scriptProperties,true)) {
    $albumRequestVar = $modx->getOption('albumRequestVar',$scriptProperties,'galAlbum');
    if (!empty($_REQUEST[$albumRequestVar])) $album = $_REQUEST[$albumRequestVar];
// We pass the album name/ID to an &album property and find the gallery object
if (!is_int($album)) {
    $gallery = $modx->getObject('galAlbum',array('name' => $album));
    if ($gallery instanceof galAlbum)
        $album = $gallery->get('id');
$c = $modx->newQuery('galAlbumItem');
        'album' => $album,
$collection = $modx->getCollection('galAlbumItem',$c);
$items = array();
foreach ($collection as $i) {
    $items[] = $i->toArray();
$continue = true;
$i = 0; $prev = array(); $cur = array(); $next = array();
while ($continue) {
    $prev = $cur;
    $cur = $items[$i];
    if ($cur['id'] == $curItem) {
        $next = $items[$i+1];
        $continue = false;
$first = $items[0];
$last = $items[count($items)-1];
$phs['galitem.cur.'] = $cur;
$phs['galitem.prev.'] = $prev;
$phs['galitem.next.'] = $next;
$phs['galitem.first.'] = $first;
$phs['galitem.last.'] = $last;
return '';

Now set up your placeholders for the navigation:

[[!GalleryItemPagination? &album=`1`]]
[[!If? &subject=`[[!+galitem.prev.id]]`&operator=`isnotempty` &then=`
<a id="previmg" href="[[++site_url]]?id=[[*id]]&galItem=[[!+galitem.prev.id]]&galAlbum=1&galTag=">previous image</a>`]]
[[!If? &subject=`[[!+galitem.next.id]]`&operator=`isnotempty` &then=`
<a id="nextimg" href="[[++site_url]]?id=[[*id]]&galItem=[[!+galitem.next.id]]&galAlbum=1&galTag=">next image</a>`]]

See Also

  1. Gallery.Gallery
    1. Gallery.Gallery.containerTpl
    2. Gallery.Gallery.thumbTpl
  2. Gallery.GalleryAlbums
    1. Gallery.GalleryAlbums.containerTpl
    2. Gallery.GalleryAlbums.rowTpl
  3. Gallery.GalleryItem
    1. Gallery.GalleryItem.albumTpl
    2. Gallery.GalleryItem.GalleryItemPagination
    3. Gallery.GalleryItem.tagTpl
    4. Gallery.GalleryItem.tpl
  4. Gallery.Plugins
    1. Gallery.Plugins.Galleriffic
    2. Gallery.Plugins.Slimbox
  5. Gallery.Setting Up Your Gallery
  6. Gallery.Example1
  7. Gallery.Setting Up the GalleryItem TV