We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22385
    • 17 Posts
    Trying to get 2 different outputs from one single snippet calling it just once on the page.

    This snippet is a RSS parser and works well.
    Try to show the 10 first items on the top of the page and then, after some other content in the middle, show all the rest items on the bottom of the page.

    I could call twice the snippet but it crashes and also doesn’t find it optimal since the bottom items are the continuation of the first output result (items) on the top of the page.

    Eventually I’d add a paginator too to split the bottom items in various pages.

    I wanna believe there’s a straight forward solution for this but didn’t find anything on the documentation nor the forum.
    Many thanks!!
      • 4971
      • 964 Posts
      Maybe use an array as the output and
      then extract each of your outputs in the
      code outside???
        Website: www.mercologia.com
        MODX Revo Tutorials:  www.modxperience.com

        MODX Professional Partner
        • 1778
        • 659 Posts
        In the snippet you wrote you can :
        Set a placeholder with the result you want to display (eg the 10 first on the top of your page), call it for example ’top10’
        Set another one with the rest of the result, call it for example ’bottomRSS’

        Then in you resource (or template) you call once you snippet, and display results via the placeholders you created...
        Hope it helps
        Cheers
          • 22385
          • 17 Posts
          Ok, I see the logic on your answer, I tried it but didn’t get it working sad

          This is what I got so far:
          foreach ( $rss->items as $item ) {
             $modx->setPlaceholder("title", $rss->items[$i]['title']);
             $modx->setPlaceholder("logo", $rss->items[$i]['kd']['imagelink']);
             if (($i<$limit)&&($i>=$initial)) {
               $outputFirst .= $modx->parseChunk($tplChunk, $modx->placeholders, '[+', '+]');			  
             }
             else if (isset($split)) {
               $outputRest .= $modx->parseChunk($tplChunk, $modx->placeholders, '[+', '+]');
             }
             $i++;
          }
          $output[1] = $modx->setPlaceholder("Top10", $outputFirst);
          $output[2] = $modx->setPlaceholder("Rest", $outputRest);
          		
          //return $output;
          return $output;
          


          Then on the resource I call the snippet and the two placeholders but doesn’t output anything.
          I did several tryout and the snippet works just fine but there’s something wrong at parsing these placeholders, return them or call them from the resource.

          Many thanks both of you!!
            • 4971
            • 964 Posts
            Your are mixing both our answers.
            I think it will work if you implement
            one or the other.
              Website: www.mercologia.com
              MODX Revo Tutorials:  www.modxperience.com

              MODX Professional Partner
              • 22385
              • 17 Posts
              Maybe Charliez.
              Can you put me a simplified example of your solution?
              Thanks again.