We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28288
    • 5 Posts
    I’m fiddling around with Mode Revo. 2.x and the new API. I’ve created a small ’test’ snippet containing the code below:

    <?php
      $criteria = $modx->newQuery('modResource');
      $criteria->where(array('parent' => $parent));
      $criteria->sortby('publishedon','DESC');
      $criteria->limit(3,0);
      $children = $modx->resource->getMany('Children',$criteria);
    
      foreach ($children as $child)
      {
         $year=date('Y', strtotime($child->get('publishedon')));
         $month=date('m', strtotime($child->get('publishedon')));
         $day=date('d', strtotime($child->get('publishedon')));
         $permalink=$child->get('alias');
    
         echo '<div id="header_' . $child->get('pagetitle') . '">' . $child->get('pagetitle') . '</div>' . "\n";
         echo '<div class="front_page_item_date">' . date('F jS, Y', strtotime($child->get('publishedon'))) . '</div>' . "\n";
         echo '<div class="front_page_item_header">' . $child->get('pagetitle') . '</div>' . "\n";
         echo '<div class="front_page_item_content">' . substr($child->get('content'), 0, 512)  . '...</div>' . "\n";
         echo '<div id="front_page_item_comments_' . $child->get('pagetitle') . '">0</div>' . "\n";
         echo '<div class="front_page_item_read_more"><a href="http://www.website.com/' . $category . '/articles/' . $year . '/' . $month . '/' . $day . '/' . $child->get('alias') . '">Read more...</a></div>' . "\n";
      }
    ?>
    


    When I call the same snippet multiple times on the same page every instance of the same snippet gives exact the same result:
    [[test? &category=CatA &parent=6]]
    [[test? &category=CatB &parent=7]]
    [[test? &category=CatC &parent=8]]
    


    I’ve turned all the caching meganisms of in the manager. But it stil seems there are things cached. Is this a bug or a feature in MODx Revo. 2.x. If it’s a feature could some give me a hint to solve this?



    <?php
      $criteria = $modx->newQuery('modResource');
      $criteria->where(array('parent' => $parent));
      $criteria->sortby('publishedon','DESC');
      $criteria->limit(3,0);
      $children = $modx->resource->getMany('Children',$criteria);
    
      foreach ($children as $child)
      {
         $year=date('Y', strtotime($child->get('publishedon')));
         $month=date('m', strtotime($child->get('publishedon')));
         $day=date('d', strtotime($child->get('publishedon')));
         $permalink=$child->get('alias');
    
         echo '<div id="header_' . $child->get('pagetitle') . '">' . $child->get('pagetitle') . '</div>' . "\n";
         echo '<div class="front_page_item_date">' . date('F jS, Y', strtotime($child->get('publishedon'))) . '</div>' . "\n";
         echo '<div class="front_page_item_header">' . $child->get('pagetitle') . '</div>' . "\n";
         echo '<div class="front_page_item_content">' . substr($child->get('content'), 0, 512)  . '...</div>' . "\n";
         echo '<div id="front_page_item_comments_' . $child->get('pagetitle') . '">0</div>' . "\n";
         echo '<div class="front_page_item_read_more"><a href="http://www.website.com/' . $category . '/articles/' . $year . '/' . $month . '/' . $day . '/' . $child->get('alias') . '">Read more...</a></div>' . "\n";
      }
    ?>
    


    When I call the same snippet multiple times on the same page every instance of the same snippet gives exact the same result:
    [[test? &category=CatA &parent=6]]
    [[test? &category=CatB &parent=7]]
    [[test? &category=CatC &parent=8]]
    


    I’ve turned all the caching meganisms of in the manager. But it stil seems there are things cached. Is this a bug or a feature in MODx Revo. 2.x. If it’s a feature could some give me a hint to solve this?
      • 28215
      • 4,149 Posts
      Did you try:

      [[!test? &category=`CatA` &parent=`6`]]
      [[!test? &category=`CatB` &parent=`7`]]
      [[!test? &category=`CatC` &parent=`8`]]
      


      (By the way, you really should be using backticks ` in properties.)
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 28288
        • 5 Posts
        I’ve added the backticks but this doesn’t solve it.

        I’ve also tried to store all the output to a variable and use the return $output; statement and that doesn’t solve it neither.
          • 28215
          • 4,149 Posts
          You added the ! to make it uncached?

          Plus - don’t echo. Return the output stored in a variable.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 28288
            • 5 Posts
            You added the ! to make it uncached?
            Yes I’ve tried everything to turn of caching also by placing the ’!’ in front of the snippet name.

            Plus - don’t echo. Return the output stored in a variable.
            Indead I’ve read that in another post. I won’t do that again and put everythin in a variable and return it. (But stil no clue what’s going wrong embarrassed )
              • 28215
              • 4,149 Posts
              Try changing:

              $children = $modx->resource->getMany('Children',$criteria);


              To:

              $children = $modx->getCollection('modResource',$criteria);


              You’re trying to use getMany with a criteria that changes parents on a Resource that already has a parent; there’s no reason to use getMany here.
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 28288
                • 5 Posts
                Yeh!!! laugh Great stuff this solved the problem thanks you very much!