We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36783
    • 3 Posts
    Hi, I tried to create an image gallery with pagination based on this tutorial:
    http://rtfm.modx.com/extras/revo/migx/migx.tutorials/migx.use-resource-specific-mediasource-and-multifile-uploader
    And everything works fine so far. But only one thing drives me crazy. Inside the template where I used to show the items, I would also like to add the number of the item in the title - e.g. title="Foto #[[+idx]]".
    I guessed the placeholder [[+idx]] would do the job and it does. But since I have a &limit parameter set and use the pagination, the idx seems to be reset to 1 on every page from pagination.
    Is there something trivial that I'm missing or missunderstood - please have a look to my code below.

    <div>
    [[!getPage?
    &element=`getImageList`
    &tpl=`GalleryTmpl`
    &limit=`24`
    &tvname=`resourcealbum`
    &pageVarKey=`page`
    &pageNavVar=`page.nav`
    &totalVar=`total`
    ]]
    </div>
    
    <div class="text-center">
    <ul class="pagination">[[!+page.nav]]</ul>
    </div>
    


    GalleryTemplate
    [[+image:notempty=`
    <div class="col-xs-4 col-sm-3 col-md-2 col-lg-2">
    <a class="thumbnail" href="[[+image]]" title="Foto #[[+idx]] [[+title]]" data-gallery="">
    <img id="[[+idx]]_gallery_image" src="[[+image:phpthumbof=`w=120&h=100`]]"  />
    </a>
    </div>`]]
    


    Thank you in advance and best regards!
    Alex
      • 4172
      • 5,888 Posts
      with this snippet you can add another idx to all items:

      <?php
      
      //[[add_idx2? &items=`[[*migxtv]]`]]
      
      $items = $modx->fromJson($items);
      
      $out = array();
      if (is_array($items)){
          $idx = 1;
          foreach ($items as $item){
              $item['idx2'] = $idx;
              $out[] = $item;
              $idx++; 
          }
      }
      
      return $modx->toJson($out);
      


      Use it like that:

      [[!getPage?
      &element=`getImageList`
      &tpl=`GalleryTmpl`
      &limit=`24`
      &value=`[[add_idx2? &items=`[[*resourcealbum]]`]]`
      &tvname=`resourcealbum`
      &pageVarKey=`page`
      &pageNavVar=`page.nav`
      &totalVar=`total`
      ]]


      [[+image:notempty=`
      <div class="col-xs-4 col-sm-3 col-md-2 col-lg-2">
      <a class="thumbnail" href="[[+image]]" title="Foto #[[+idx2]] [[+title]]" data-gallery="">
      <img id="[[+idx2]]_gallery_image" src="[[+image:phpthumbof=`w=120&h=100`]]"  />
      </a>
      </div>`]]
      


      does this work?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36783
        • 3 Posts
        Hey Bruno,
        works like a charm! Very elegant and reusable solution, that provide me also with a solution for another idea.

        Before I tried different approaches - one of them was for example to use output filter and later a simple own snippet in order to calculate the number inside the chunk passing available values for "limit", "page" and "idx" placeholder (limit * (page -1) +idx) as parameters.
        But it seems not to be supported like this - so it was a bad idea.

        Thank you very much!