We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8634
    • 56 Posts
    I don’t know if this possible and more importantly how to make it happen. I’ve a test site for my Division’s website at www.prwiki.org. When you refresh the page you will see that the image and quote change randomly. However the quote is not connected to the image while ideally it should. Does anyone have an idea how I can randomy display an image with accompanying quotes which as you may have seen on the site are displayed in different divs (I use CSS positioning, even though I’m not very conversant with it..)

    Thanks
      • 32963
      • 1,732 Posts
      Hmmm,

      One eway to do this is to create a folder and in that folder create documents that would contain images and text. Then create a snippet or a TV (using @EVAL) to randomly display the content of documents inside the folder.

      The other way is to wait until the Content Rotator TV control is released. No timelines on it’s release as yet smiley
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 8634
        • 56 Posts
        The problem is that this display of content would be in different areas, so split in two, the image in the top area and the quote in the below area which is defined by a different div. I don’t think that the "future" content Rotator TV control could do this either. Maybe I’m just asking for the "impossible"
          • 19726
          • 239 Posts
          I just did a small test with 2 snippets which seems to do what you want. I have one snippet that generates a random number and puts it in a global. Then I have a second snippet that picks up the random number.

          Snippet 1
          $GLOBALS['somevarname'] = rand(0,10);
          
          return '<h1>'.$GLOBALS['somevarname'].'</h1>';


          Snippet 2
          if (isset($GLOBALS['somevarname']))
          {
            return '<h1>'.$GLOBALS['somevarname'].'</h1>';
          }
          else
          {
            return 'Global was not set';
          }
          • Another approach is to use a single snippet to get the values you want to output, and then assign them to placeholders...

            //magic code here to get random image and related text
            $modx->setPlaceholder('theImage', $imageOutput);
            $modx->setPlaceholder('theText', $textOutput);


            and then in your content, or template, or various template vars, you can use those placeholders to place the output exactly where you want it...

            [[RandomImageAndQuoteSnippet]]
            
            ...
            
            
            <div id="uptop">[+theImage+]</div>
            
            ...
            
            
            <div id="downhere">[+theText+]</div>
              • 19726
              • 239 Posts
              Cool, I like the placeholder thing much more than my solution. Didn’t know it existed grin
                • 4095
                • 372 Posts
                Hey guys, I was looking for a way to just randomise text and found this post.

                Thought I’d share my solution although it wont help Eko40 since it doesn’t deal with images, it might help someother newbie like me who is searching these posts.

                The original Snippet is from Syn and I just modified it. See more at http://www.etomite.org/forums/index.php?showtopic=1396&st=0&p=18668&#entry18668


                $quote[] = "Text 1";
                $quote[] = "Text 2";
                $quote[] = "Text 3";
                $quote[] = "Text 4";
                
                if(!isset($id)) {
                   $id = $modx->documentIdentifier;
                }
                
                if ($id == '1') {
                 return "Text for Page 1";
                }
                
                else
                 if ($id == '6'){
                 return "Text for Page 6";
                }
                
                else {
                 $randomquote = rand(1, count($quote));
                 return $quote[$randomquote];
                }
                


                I then call it with [!SnipetName!] so it doesn’t cache the 1st result, which stops it being random smiley

                Briggsy
                  [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                  Admin Sandbox Login: sandbox Password: castle
                  • 7455
                  • 2,204 Posts
                  mm briggsy be carefull posting modx snippets on eto forums
                  eto snippets work 99% in modx but the otherway around it does not work at all:

                  hxxp://www.etomite.org/forums/index.php?showtopic=1396&st=0&p=18668&#entry18668

                  $id = $modx->documentIdentifier;
                  
                    follow me on twitter: @dimmy01
                    • 4095
                    • 372 Posts
                    oops good point.... forgot

                    I changed the code on Etomite site as I only altered the orginal etomite code in the first place. Does Etomite use [!snippet!] or simillar to call a non cached version?

                    Thanks for the reminder, forgot they aren’t all as lucky as we are wink

                    Briggsy
                      [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                      Admin Sandbox Login: sandbox Password: castle
                    • Etomite does use the [! syntax as well.
                        Ryan Thrash, MODX Co-Founder
                        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me