We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42101
    • 125 Posts
    Hi!

    I am trying to get an external RSS feed call from one snippet into another.

    I found something about it, but it was 7 years old...for evo - so maybe it's now more easy?

    I tried it with "real" php files - and it works.

    In modx revo I created a snippet like this:

    require_once('getRss.php');
    echo fetchFeed('http://www.amazon.de/rss/...');


    It gets the "getRss.php" - but is it possible to easily include it from the snippets?

    the contents are:
    <?php
    function fetchFeed($feed_url){
    $output = '';
    $content = file_get_contents($feed_url);
    $feeditems = new SimpleXMLElement($content);
    foreach($feeditems->channel->item as $entry){
    $output .= "<a style='$color' href='$entry->link' title='$entry->title'>" . $entry->title . '</a><br />';
    }
    return $output;
    }
    


    I tried to make it static..but it is not the same...

    Thank you!

    AD
      • 29661
      • 116 Posts
      Hello,

      I think you can make snippet right from content that you posted:
      <?php
      $output = '';
      $content = file_get_contents($feed_url);
      $feeditems = new SimpleXMLElement($content);
      foreach($feeditems->channel->item as $entry){
      $output .= "<a style='$color' href='$entry->link' title='$entry->title'>" . $entry->title . '</a><br />';
      }
      return $output;


      You can name it for example getRss and you can call it with feed_url parameter to parse selected URL, example call could look like [[!getRss? &feed_url=`http://www.amazon.de/rss`]].

      If you want to call this snippet from some other snippet, you can use MODx api method runSnippet that is described here: http://rtfm.modx.com/display/revolution20/modX.runSnippet

      And I strongly recommend to not mix html and php code in snippet. Create a chunk and parse output by chunk. More about parsing chunks is here: http://rtfm.modx.com/display/revolution20/modX.getChunk and http://rtfm.modx.com/display/revolution20/modX.parseChunk
        --
        John
        @theboxer
        • 42101
        • 125 Posts
        Quote from: TheBoxer at May 07, 2013, 04:18 PM
        Hello,

        I think you can make snippet right from content that you posted:
        <!--?php
        $output = '';
        $content = file_get_contents($feed_url);
        $feeditems = new SimpleXMLElement($content);
        foreach($feeditems--->channel->item as $entry){
        $output .= "<a style="$color" href="$entry->link" title="$entry->title">" . $entry->title . '</a>
        ';
        }
        return $output;



        Hi John,

        thank you very much for the suggestions and links!

        [[!getRss? &feed_url=`http://www.amazon.de/rss`]]

        "Ay caramba!"
        It's working. smiley

        Thank you!!!

        AD