We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Dear MODX people,

    if you have a gallery and would like the first image of an album to use another template than all others, you can do it like this:

    In your gallery call, you have the thumbnail template chunk mentioned like this:
    &thumbTpl=`galItemThumb`

    So just add this line to pass a new variable to the gallery script which contains the new template for the first image:
    &firstThumbTpl=`galItemThumbFirst`


    Now, in your snippets, go to gallery folder and open "Gallery". Scroll down to the place near
    $idx++;


    Now, edit the lines before that like this:
        $output[] = $gallery->getChunk($modx->getOption('thumbTpl',$scriptProperties,'galItemThumb'),$itemArray);
        $idx++;

    The lines above become these:
       if ($idx=="0") {
        $output[] = $gallery->getChunk($modx->getOption('firstThumbTpl',$scriptProperties,'galItemThumbFirst'),$itemArray);
    }
        else {
        $output[] = $gallery->getChunk($modx->getOption('thumbTpl',$scriptProperties,'galItemThumb'),$itemArray);
    }
        $idx++;


    That's it. When the Gallery Script displays the first image of an album, it will read and output another template chunk for it and still work the same. To have different image sizes (first image is big) this could look like this:
    galItemThumb
    <div class="[[+cls]] box frame">
        <a href="[[+image_absolute]]" title="[[+name]]" class="cb" [[+link_attributes]]>

    <img class="[[+imgCls]]" src="[[+image_absolute:pthumb=`w=288&h=288&zc=1`]]" alt="[[+name]]" [[+image_attributes]] />
    </a>
    </div>
    and the modified (other image size) [b]galItemThumbFirst[/b]
    <div class="[[+cls]] box frame">
    <a href="[[+image_absolute]]" title="[[+name]]" class="cb" [[+link_attributes]]>

    <img class="[[+imgCls]]" src="[[+image_absolute:pthumb=`w=928&h=928&zc=1`]]" alt="[[+name]]" [[+image_attributes]] />
    </a>
    </div>
    Hope you can use it if you found it here. Cheers, Guido
      • 38290
      • 712 Posts
      Seems like with a slight alternation to only use the firstThumbTpl if supplied this could be a great pull request. We are excepting pull requests for Gallery over at:
      https://github.com/modxcms/Gallery/pulls

      $firstThumbTpl = $modx->getOption('firstThumbTpl',null,$properties);
      if (isset($firstThumbTpl) && $idx=="0") {
          $output[] = $gallery->getChunk($modx->getOption('firstThumbTpl',$scriptProperties,'galItemThumbFirst'),$itemArray);
      }
      else {
          $output[] = $gallery->getChunk($modx->getOption('thumbTpl',$scriptProperties,'galItemThumb'),$itemArray);
      }
      $idx++;
        jpdevries
      • Right, I did it the quick and dirty way. I dont use github, how do I make this pull request?
          • 38290
          • 712 Posts
          Quote from: gallenkamp at Dec 02, 2013, 08:34 PM
          Right, I did it the quick and dirty way. I dont use github, how do I make this pull request?

          You have to be on GitHub to submit pull requests (be careful because it gets addictive). I can create a test branch with your modifications in preparation to be included with the next release and post back here when it has been merged.
            jpdevries
          • Wouldnt it be better to add options like "tpl for last image" and "tpl nTh image" before creating a pull request?
              • 38290
              • 712 Posts
              Quote from: gallenkamp at Dec 02, 2013, 08:52 PM
              Wouldnt it be better to add options like "tpl for last image" and "tpl nTh image" before creating a pull request?

              I think first and last makes sense. Supporting nTH image might get a little complicated. I'm curious if using a snippet for that that somehow fetched the data from Gallery and processed it there, rather than having Gallery do it would make more sense. Are there any other Extras you know of that support nTH for templating, just curious how it would be done.
                jpdevries
              • As far as I remember, getResources has it.as far as I know getResources has this feature. it cant be that hard to integrate. More than like "Can you divide $idx by n? Fine, use this template..." smiley
                • I currently needed this function but I didnt put the pull request back then. What is the current repository for this?