We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34120
    • 236 Posts
    I’ve got a snippet that reads images from a directory and creates an array. I then want to use this array to generate a list to be used with jquery to produce a simple sequence of rolling images. The problem is I can’t get the array values to output on my page.

    I can’t run xampp at the moment so I don’t have full access to the code. Here’s roughly how my page looks. I’m working with revolution rc3. I’ve a feeling it’s something to do with the variables not being passed to the [[generateList]] snippet.

    [[readImgDir]] <!-- this reads the images from a directory and creates an array, I can echo from here just fine -->
    <html>
    <head>
    <title>Image Fader</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="/examples/jquery.innerfade.js"></script>
    </head>
    <body>
    <ul id="image_rotate" style="list-style: none;">
    [[generateList]] <!-- this snippets contains a simple 'echo $image_array;' The image array is created in the first snippet on this page. The problem is here, nothing is outputted -->
    </ul> 
    </body>
    </html>


    Hopefully that will be enough to go on.
    This is code I’m working with http://www.linein.org/blog/2008/01/10/roate-image-using-jquery-with-plugin/

    I will post the full code later on if needed.

    Many thanks, sorry it’s a bit vague.
      • 3749
      • 24,544 Posts
      Try setting a $_SESSION variable with the first snippet and save the array in it:

      $_SESSION['MyData'] = $image_array;


      Then retrieve it in the second snippet with:

      $image_array = $_SESSION['MyData'];


      BTW, it’s better for the second snippet to put all the output in a variable ($output) and return that than echoing it.

      return $output;
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 34120
        • 236 Posts
        Thanks for the reply Bob, I must have been having a funny day yesterday.
        I’ve changed the second snippet to "return $output;" and used the following
        <ul id="image_rotate" style="list-style: none;">  
        [[generateList? &images=`[[readImgDir]]`]]
        </ul> 

        Quickly tested and it seems to work, I think my brain had slipped back to my old ways of having php code at the start of the page etc.

        Thanks again