On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • This is a topic for getImages by jerry325

    Description
    This Snippet retrieves image files from a directory, processes them through a
    template chunk and returns the results.

    Parameters

    &folder string - The name of the image folder to search. optional. Default: assets/photos
    &ext string - The extension(s comma separated list) of the images. optional. Default: *.jpg
    &tpl string - The name of a Chunk used to format output. optional. Default: getImagse_Tpl
    &limit integer - A number representing how many images to return. optional. Default: 6
    &offset integer - A number representing where to start the next return. optional. Default: 6
    &width integer - A number representing the width images to return. optional. Default: 150
    &height integer - A number representing the height images to return. optional. Default: 100
    &border integer - A number representing the border width. optional. Default: 0
    &class string - A class name to pass. optional. Default: ''

    Usage
    Place the following snippet call into the page or chunk where you would like the images to
    appear. You can use the helper Snippet getImagesFolder to pull a folder name from the URL.
    When used with getFolders, getFoldersList, and getPage it becomes a complete Photo Gallery
    solution that will grab all the images from a given folder structure and return Gallery pages
    based on that folder structure.

    [[!getImages?
    &getImages_Folder=`assets/photos`
    &getImages_Ext =`*.jpg,*.png`
    &getImages_Tpl =`getImages_Tpl`
    &getImages_Limit =`6`
    &getImages_Offset =`8`
    &getImages_Width =`150`
    &getImages_Height=`100`
    &getImages_Border=`2`
    &getImages_Class =`img`
    ]]

    All vars are optional


    Release Notes
    This sprang out of my rewrite of my "myGallery" Snippet. I was disappointed with the Gallery packages out
    there as I wanted to be able to simply add images and thumbnails to a directory via FTP and have them show
    up. It worked well but as I added more and more directories I found I had to create new pages and I'm far
    too lazy for that. I wanted to be able to make a page by simply scanning the folder structure that was
    uploaded via FTP and use the folder names as page names. I used my getFolders Snippet to get the folder
    structure and my getFoldersList Snippet to create a menu from that folder structure. I then used my
    getImagesFolder Snippet to pull the needed folder from the URL that the menu passed and then fed the results
    through Jason Coward's great getPage Snippet and I was in business. It sounds far more complicated than it
    is and it works like a dream. As always I would be grateful for any and all suggestions for improvements.
    • How about a random image or images? Not to mention a random image from a random folder. Or a random image from each folder. Or a random image from a specified folder... wink
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
      • I have such a beast but just haven't packaged it yet. I'll get on that and let you know when it's up.
        • I have just submitted randImages and hopefully it will be available soon. If you would like it now I can send you the transport zip.
          • I'm not in any hurry; this is something I will probably be able to use with a site I'll be working on later.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
            • Well a little over 100 downloads and no bugs reported. Time to mark this one pl.
              I did add an example CSS file and changed the way the extensions are entered.

              Should you find any issues or have an idea to make this better, just let me know
              • hi,
                trying to work with getimages with modx revolution 2.2.8 but i cant figure how template (&getImages_Tpl) works and what it contain

                i try
                [[!getImages? &getImages_Folder=`images/gallerie/team/` &getImages_Tpl =`GalerieRowTpl` &getImages_Ext =`*.jpg,*.png`&getImages_Limit =`6`&getImages_Offset =`8`&getImages_Width =`150`&getImages_Height=`100`&getImages_Border=`2`&getImages_Class =`img`]]

                but it's doing nothing

                i have getfolder and getpage installed

                can you tell me how to manage that ?

                thanks.
                • Quote from: singaii at Sep 18, 2013, 01:03 PM
                  hi,
                  trying to work with getimages with modx revolution 2.2.8 but i cant figure how template (&getImages_Tpl) works and what it contain

                  i try
                  [[!getImages? &getImages_Folder=`images/gallerie/team/` &getImages_Tpl =`GalerieRowTpl` &getImages_Ext =`*.jpg,*.png`&getImages_Limit =`6`&getImages_Offset =`8`&getImages_Width =`150`&getImages_Height=`100`&getImages_Border=`2`&getImages_Class =`img`]]

                  but it's doing nothing

                  i have getfolder and getpage installed

                  can you tell me how to manage that ?

                  thanks.

                  This is what I use for my getImages_Tpl

                  <div class="photos">
                  <a href="[[+imgLink]]" target="_blank">
                  <img title="[[+image]]" src="[[+path]].thumbs/lr_[[+imgFile]]" alt="[[+imgLink]]" width="[[+width]]" height="[[+height]]" />
                  </a>
                  </div>

                  The first line is a link to open a new page with the full sized image.
                  The next actually grabs the image thumbnail using the image name that it collected from the full sized image folder and since all my thumbnails are in a hidden subfolder called .thumbs and have a prefix of lr_ it adds this so the path is correct. However I see that you are not using a thumbnail folder so yours should be

                  <div class="photos">
                  <a href="[[+imgLink]]" target="_blank">
                  <img title="[[+image]]" src="[[+imgLink]]" alt="[[+imgLink]]" width="[[+width]]" height="[[+height]]" />
                  </a>
                  </div>
                  • With some prompting from Norman I discovered a Typo or two in one of my example templates. It seems I used a lower instead of an uppercase L in the placeholder [[+imgLink]] and the result was no images appearing. I also noted that no images were being found in a test directory I had created and after a bit of hair pulling I noticed that the image extensions were in uppercase. I thought maybe a few of you might be having a similar issue so I set the default extension to be `jpg,gif,png,JPG,GIF,PNG` that way the most common file names would be found "out of the box" Thanks so much for using my snippet and keep asking questions when you need help. I learn more that way. smiley
                    • Great snippet, thanks. Is it possible to get hold of the image name without the extension in a template chunk? It would be nice to be able to use that as the alt text.