We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12793
    • 293 Posts
    Thanks for your replies.

    Suppose that I like this carousel:

    http://nouincolor.com/floom/1.1/Demos/


    or this:

    http://nivo.dev7studios.com/demos/


    How Can I make it working reading images from a specified folder?

    Thanks
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Write a snippet to read the folder using any of the PHP functions that will do this, and have the snippet output each filename into the HTML required. For example, the first one you link to has this:
      <div id="blinds-cont">
      		<div id="blinds">
      
      			<!-- <img title="Lorem ipsum dolor sit amet, consectetur adipisicing elit" alt="" src="nature-photo0.jpg" />
      			<img title="Lorem ipsum dolor sit amet, consectetur adipisicing elit" alt="" src="nature-photo1.jpg" />
      			<img title="Lorem ipsum dolor sit amet, consectetur adipisicing elit" alt="" src="nature-photo2.jpg" />
      			<img title="Lorem ipsum dolor sit amet, consectetur adipisicing elit" alt="" src="nature-photo3.jpg" />
      			<img title="Lorem ipsum dolor sit amet, consectetur adipisicing elit" alt="" src="nature-photo4.jpg" /> -->
      		</div>
      	</div>
      

      So you’ll want to have this HTML
      <div id="blinds-cont">
      		<div id="blinds">
      
      			<!-- [[SnippetName? &folder=`folder1`]] -->
      		</div>
      	</div>
      

      The snippet will be something like this:
      <?php
      $dir = "assets/images/".$folder;
      $output = '';
      if (is_dir($dir)) {
          if ($dh = opendir($dir)) {
              while (($file = readdir($dh)) !== false) {
                  if(filetype($dir.$file) == 'file') && $file != '.' && $file != '..')
                  $info = pathinfo($file);
                  $file_name =  basename($file,'.'.$info['extension']);
                  $output .= '<img title="'.$file_name.'" alt="" src="'.$dir.$file'" />';
              }
              closedir($dh);
          }
      }
      return $output;
      ?>
      
        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
        • 12793
        • 293 Posts
        Greeeat!!!
        Thank you .... so I’ve only create my HTML

        <div id="blinds-cont">
        <div id="blinds">

        <!-- [[SnippetName? &folder=`folder1`]] -->
        </div>
        </div>


        and use your snippet for read image


        OK?

        Thanks

          • 12793
          • 293 Posts
          Quote from: il_dandi at Apr 15, 2011, 03:15 PM

          Greeeat!!!
          Thank you .... so I’ve only create my HTML

          <div id="blinds-cont">
          <div id="blinds">

          <!-- [[SnippetName? &folder=`folder1`]] -->
          </div>
          </div>


          and use your snippet for read image


          OK?

          Thanks



          is it right what I’ve written ... I don’t know if this is the right way!

          Thanks
            • 33968
            • 863 Posts
            What did you name your snippet when you saved it?
            And what is the full path to your image folder?
              • 12793
              • 293 Posts
              snippet name is "carousel"

              all my carousel images are in:

              assets/templates/my_template/carousel

                • 33968
                • 863 Posts
                So you need to change the snippet call to carousel smiley

                Also, the snippet is expecting your image folder to be under assets/images/. So move your ’carousel’ folder to assets/images/carousel/, then call it like this:
                <div id="blinds-cont">
                      <div id="blinds">
                
                         <!-- [[carousel? &folder=`carousel`]] -->
                      </div>
                   </div>
                

                  • 12793
                  • 293 Posts
                  I’ve created this snippet

                  <?php
                  $dir = "assets/templates/mytemplage_v1/".$folder;
                  $output = ’’;
                  if (is_dir($dir)) {
                  if ($dh = opendir($dir)) {
                  while (($file = readdir($dh)) !== false) {
                  if(filetype($dir.$file) == ’file’) && $file != ’.’ && $file != ’..’)
                  $info = pathinfo($file);
                  $file_name = basename($file,’.’.$info[’extension’]);
                  $output .= ’<img title="’.$file_name.’" alt="" src="’.$dir.$file’" />’;
                  }
                  closedir($dh);
                  }
                  }
                  return $output;


                  created my carousel folder in assets assets/templates/mytemplage_v1/

                  and inserted this HTML tag


                  <!-- [[carousel? &folder=`carousel`]] -->


                  But I show an empty page with this HTML sad(((


                  another thing: why in your example do you use these div:

                  <div id="blinds-cont">
                  <div id="blinds">


                  Thanks

                    • 33968
                    • 863 Posts
                    I only added those divs as those are what you had in your markup above.

                    You have this line in your snippet:
                    $dir = "assets/templates/mytemplage_v1/".$folder;

                    Which appends whatever you put in &folder=`` in your snippet call to the path in the snippet above. That’s useful if you intend to use this snippet more than once and for different folders.

                    So:
                    [[carousel? &folder=`carousel` ]] will point to assets/templates/mytemplage_v1/carousel/.
                    [[carousel? &folder=`` ]] will point to assets/templates/mytemplage_v1/

                    If you’re only going to use it once, just call it [[carousel]] and change the first line in your snippet to:
                    $dir = "assets/templates/mytemplage_v1/";

                      • 12793
                      • 293 Posts
                      Yes!! Is what I’ve done... but not working:

                      in my snippet I’ve

                      $dir = "assets/templates/myfolder_v1/".$folder;

                      in myfolder_v1 I’ve a "carousel" folder with all my images


                      in code I’ve inserted (on Revo)


                      <!-- [[carousel? &folder=`carousel`]] -->

                      Do I’ve to keep <!--?? (I’ve tried with or without HTML comments and doesn’t works)


                      I show an empty page when I insert this string in my HTML