We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7869
    • 118 Posts
    I used FeedX to get data from an RSS feed, but I’d like to change some of that data before it gets displayed. For example if one of the output items was a link that looked like this:

    [tt]http://www.example.com/item/product?id=1000[/tt]

    and I wanted to change it to this before outputting on the web page

    [tt]http://www.example.com/1000[/tt]

    How would you go about that? Perhaps create a new snippet that would call the FeedX snippet and then use php str_replace in this new snippet to change the value of FeedX output? Confused... huh
      -Dorian
    • Perhaps create a new snippet that would call the FeedX snippet and then use php str_replace in this new snippet to change the value of FeedX output
      Yeah, you can create a wrapper snippet and use $modx->runSnippet() to run the FeedX snippet, capture the output into a variable and then manipulate to your heart’s content.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 7869
        • 118 Posts
        Anyone who has ready any of my posts knows I’m really bad at understanding coding and stuff. rolleyes

        Any chance you can start me out on what this snippet should look like. I am really bad until I get a visual example at which point I am just bad (but something is better than nothing). wink
          -Dorian
          • 7869
          • 118 Posts
          Gee, thanks! I didn’t get it working exactly as I want to, but definitely got something working. smiley
          You haven’t heard the last of me!
            -Dorian
            • 12658
            • 9 Posts
            I’ve been trying to do something very similar to this but I haven’t been able to get it to work.

            I have an RSS feed being imported via FeedX. It pulls everything in fine though it looks really ugly. wink

            I need to change the [+SOURCE+] variable.
            simply: If [+SOURCE+] == ’twitter’ then [+SOURCE+] Twitter Update.

            So far I have the following:
            FeedX is installed and working perfectly.
            FeedX snippet is properly installed.
            I created a FeedXmod snippet with the following code (probably totally wrong syntax):
            <?php
            $source->runSnippet('FeedX', array('param1'=>var1); //I have no idea what the param1 and var1 should be, if this is even right at all)
            if ($source == 'twitter'){
            $source = 'Twitter Update';
            }
            ?>

            I am assuming (once the param1 and var1 are fixed) $source = [+source+] created by FeedX.

            Once again, I am trying to intercept the [+SOURCE+] variable and modify it before it’s put on the page.

            Hopefully that made sense. huh
            • First, that has to be $modx->runSnippet, since the runSnippet function is a part of the $modx object.
              $source = $modx->runSnippet(...)

              takes the normal output of the snippet and puts it into the variable $source. Then you can do whatever you want to that variable’s contents.

              The runSnippet function takes two parameters. The first is the name of the snippet. The second is an array of the snippet’s parameters. The param1 would be the &param part of a parameter, and the var1 would be that parameter’s value; whatever you put in the snippet tags as &param1=`var1`, &param2=`var2` etc. if you’re calling the snippet directly. In the array, strings have to be enclosed in single-quotes (unlike in snippet parameters where the values have to use backticks if they have spaces)

              $source = $modx->runSnippet('FeedX', array('param1'=>'var1'));


                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 12658
                • 9 Posts
                Thank you! I updated the code to:
                <?php
                $source = $modx->runSnippet('FeedX', array('source'=>$source);
                if ($source == 'Twitter / iDmatt'){
                $source = 'Twitter Update';
                }
                ?>

                I’m still confused about the array though. The FeedX snippet creates a whole lot of code, not just a few variables. It takes the RSS feed, sets each piece of data as a variable (such as [+SOURCE+] then ouputs it according to a .tpl file. Within the tpl file you place something like... [+TITLE+] was posted on [+DATE+].

                You said the array needs param and a value. I am guessing the param is [+SOURCE+]? and the value I’m not sure of because it’s always different - it’s what I’m changing.

                But... FeedX uses the following when you call it:

                [!FeedX? &url=`urlhere` &preset=`rss2` &caheTime=`0` &cacheType=`0` &debug=`0`!]

                source is not one of the available parameters.

                I’m just very confused about what’s happening in the whole scheme of things. I would have thought this is pretty easy to do.
                • $source = $modx->runSnippet('FeedX', array('url'=>'urlhere', 'preset'=>'rss2', ' cacheTime'=>0, 'cacheType'=>0,  'debug'=>0));

                  You might want to do a bit of studying on PHP basics, such as how PHP arrays work.

                  http://php.net/manual/en/language.types.array.php
                  http://devzone.zend.com/node/view/id/635
                  http://www.phpf1.com/tutorial/php-array.html?page=4

                  Also, you need to watch your parentheses, make sure you have closing ones to correspond to the opening ones!

                  The $source variable now contains exactly what you would get on your page if you just had the ordinary FeedX snippet call. You can use str_replace or regular expression replacement to make any changes to it that you want before returning it to the page.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 4172
                    • 5,888 Posts
                    you can also use phx in your chunk to manipulate the placeholders.
                    http://modxcms.com/extras/package/342

                    Example of use in your template(chunk):

                    [+source:is=`twitter`:then=`Twitter update`+]

                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 12658
                      • 9 Posts
                      Quote from: Bruno17 at Jul 07, 2009, 05:17 AM

                      you can also use phx in your chunk to manipulate the placeholders.
                      http://modxcms.com/extras/package/342

                      Example of use in your template(chunk):

                      [+source:is=`twitter`:then=`Twitter update`+]



                      Bingo wink grin

                      and I agree with sottwell
                      Quote from: sottwell

                      You might want to do a bit of studying on PHP basics, such as how PHP arrays work.