We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 407
    • 10 Posts
    Hi im trying to get this snippet to work:

    Set up as instructed:

    Container Documnet id=88

    documents inside - 0,1,2,3

    Call
    [!ClientQuote? &quoteid=`88`!]


    Snippet:

    <?php
    // RandomQuote
    // Snippet to produce by sottwell.
    // Posted by web_designer.
    // Dated 25th Sepember 2006.

    $resourceparent = $quoteid; // the folder that contains quote documents
    $output = ’’; // initialise the quote variable
    $resource = $modx->getActiveChildren($resourceparent,’createdon’, ’DESC’, $fields=’content’); // get array of children
    $limit=count($resource); // count how many in the array
    if($limit<1) {
    $output .= "No entries found.
    ";
    return $output;
    }
    $random = (rand(1, $limit) - 1); // make a random number between 1 and $limit, subtract 1 to allow for array counting from 0 not 1
    $output .= $resource[$random][’content’]; // grab a random document’s content from the $resource array
    return $output;
    ?>
    ?>

    Page where implemented
    http://www.icwebdesign.co.uk/new

    Any ideas why ’No entries found’ is displayed?
      • 3749
      • 24,544 Posts
      Make sure all the docs are published (or use getAllChildren() instead).
        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
        • 407
        • 10 Posts
        Thanks, how do i implement getAllChildren() ?
          • 3749
          • 24,544 Posts
          Quote from: adamchivers at Mar 16, 2009, 09:51 AM

          Thanks, how do i implement getAllChildren() ?

          Just put getAllChildren where it says getActiveChildren in the snippet.
            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
            • 407
            • 10 Posts
            Didnt work, thanks for the help. any other ideas?
              • 3749
              • 24,544 Posts
              Quote from: adamchivers at Mar 16, 2009, 11:41 AM

              Didnt work, thanks for the help. any other ideas?

              I’m running out. wink

              First, try putting this in the snippet just after the call to getAllChildren() to see if it’s getting anything:

              echo ’<pre>’;
              print_r($resource);
              echo ’</pre>’;

              Also, make sure that resourceparent and quoteid are all in lowercase letters everywhere they appear.

              Another thought is that possibly the container document (and maybe the whole path to it) need to be published.


                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
                • 29076
                • 615 Posts
                Does this snippet work with modx 0.9.6.3. at all? I just can’t get it to work. What ever I do it doesn’t show anything at all. I have to work with that to morrow. smiley
                  I think, thererfor I am! But what I am, and why...?
                  • 3749
                  • 24,544 Posts
                  Quote from: Sylvaticus at Mar 16, 2009, 05:31 PM

                  Does this snippet work with modx 0.9.6.3. at all? I just can’t get it to work. What ever I do it doesn’t show anything at all. I have to work with that to morrow.  smiley

                  I’m definitely the wrong guy to ask. I’ve never used it at all (although I can’t see anything wrong with it) and I don’t actually have an 0.9.6.3 install anywhere.  embarrassed

                  I’ve never had time to upgrade my 0.9.6.2 sites.

                  [Update] I did test it in 0.9.6 using adamchivers code from the message above pasted directly into the snippet and the following snippet call--it worked perfectly.

                  [!RandomQuotes? &quoteid=`2`!]

                  I did some testing and it doesn’t care if the container document is published. If you user getActiveChildren() it shows only published docs. If you use getAllChildren() it shows both published and unpublished docs (at least in 0.9.6).


                    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
                    • 29076
                    • 615 Posts
                    Thanks for your help. Great. smiley I’ll look into my problems with this snippet to day.
                      I think, thererfor I am! But what I am, and why...?
                      • 29076
                      • 615 Posts
                      Typo, typo, typo. It’s always a typo. Now the random snippet works. Except for one thing; the image in the TV called qouteImage don’t show. Here is the code I use:
                      $resourceparent = $quoteid;  // the folder that contains quote documents
                      $output = '';  // initialise the quote variable
                      $resource = $modx->getAllChildren($resourceparent,'createdon', 'DESC', $fields='pagetitle,content');
                      $limit=count($resource);
                      if($limit<1) {
                         $output .= "No entries found.<br />";
                         return $output;
                      }
                      $random = array_rand($resource);
                      
                      $image = $resource[$random]['qouteImage'];
                      $title = $resource[$random]['pagetitle'];
                      $text = $resource[$random]['content'];
                      
                      $output .='<img src="'.$image.'" />';
                      $output .='<p>'.$title.'</p><p>'.$text.'</p>';
                      
                      return $output;
                      ?>

                      The $resource[$random][’qouteImage’]; doesn’t seem to be the right way to get the content in the qouteImage-TV. The only thing I get is: <img src="" />.
                      I have looked in to many other snippets to see how to get the content of a TV, but with no result. Can someone please guide me here?  smiley
                        I think, thererfor I am! But what I am, and why...?