We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8542
    • 37 Posts
    Not sure if this is possible, and if it is the only method I can see is to somehow use the template to turn it into valid xml content.

    If anyone could help this would be great, or an example rss chunk. ^_^
      • 10487 MODX Staff
      • 1,535 Posts
      Sure, it’s possible to use getResources to generate an RSS feed. Here’s an example:

      Create a document, use the blank template, set the content type to XML and paste this in:
      <?xml version="1.0" encoding="utf-8"?>
      <rss version="2.0">
      <channel>
      <title>[[*pagetitle]]</title>
      <link>[[++site_url]]</link>
      <description>[[*description]]</description>
      <lastBuildDate>[[!getTime?format=`%a, %d %b %Y %H:%M:%S %z`]]</lastBuildDate>
      <language>en-gb</language>
      
      [[!getResources? 
         &parents=`3`
         &limit=`10`
         &sortby=`createdon`
         &sortdir=`DESC`
         &includeTVs=`1`
         &includeContent=`1`
         &tpl=`rssListing`
      ]]
      
      </channel>
      </rss>
      


      Adjust the &parents value to the container where you’re saving your pages that you wish to be in your RSS feed. You’ll also notice I have a getTime snippet call in there for the lastBuildDate element, that’s just a snippet that returns the current time in a particular format. The snippet content is:
      return strftime($scriptProperties['format']);
      

      Then, for the rssListing chunk, I’ve used this:
      <item>
      <title>[[+pagetitle]]</title>
      <link>[[~[[+id]]]]</link>
      <guid>[[~[[+id]]]]</guid>
      <pubDate>[[+createdon:strtotime:date=`%a, %d %b %Y %H:%M:%S %z`]]</pubDate>
      <description><![CDATA[ [[+introtext]] ]]></description>
      </item>
      

      That’s all I needed to get a basic RSS feed working on my (in-development) blog site. Hope it helps smiley
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 22303 MODX Staff
        • 10,725 Posts
        FWIW, I use a custom output filter to wrap the fields in CDATA tags (to avoid any parser issues since it ends with the double-brackets, e.g. "]]"). Here is the snippet:
        <?php
        return "<![CDATA[{$input}]]";
        ?>

        And then my tpl looks something like:
        <item>
        <title>[[+pagetitle:cdata]]</title>
        <link>[[~[[+id]]]]</link>
        <guid>[[~[[+id]]]]</guid>
        <pubDate>[[+createdon:strtotime:date=`%a, %d %b %Y %H:%M:%S %z`]]</pubDate>
        <description>[[+introtext:cdata]]</description>
        </item>
          • 8542
          • 37 Posts
          As always, thank you very much opengeek laugh.

          That really helped me out. Was trying to figure it out last night but I suppose I was too tired tongue

          And overall props to getResources. I run multiple instances of it on a single page, and have little to no page load time increase.
            • 25483
            • 741 Posts
            Quote from: OpenGeek at Feb 05, 2010, 10:00 AM

            FWIW, I use a custom output filter to wrap the fields in CDATA tags (to avoid any parser issues since it ends with the double-brackets, e.g. "]]"). Here is the snippet:
            <?php
            return "<![CDATA[{$input}]]";
            ?>

            And then my tpl looks something like:
            <item>
            <title>[[+pagetitle:cdata]]</title>
            <link>[[~[[+id]]]]</link>
            <guid>[[~[[+id]]]]</guid>
            <pubDate>[[+createdon:strtotime:date=`%a, %d %b %Y %H:%M:%S %z`]]</pubDate>
            <description>[[+introtext:cdata]]</description>
            </item>


            How do I add this output filter into MODx Revolution? Is it just a snippet with the name "cdata"?
              with regards,

              Ronald Lokers
              'Front-end developer' @ h2o Media

              • 28215
              • 4,149 Posts
              Quote from: MediaGuy at Feb 20, 2010, 08:19 AM

              How do I add this output filter into MODx Revolution? Is it just a snippet with the name "cdata"?

              Yep. Any snippet can be an output filter. See: http://svn.modxcms.com/docs/display/revolution/Input+and+Output+Filters
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 40045
                • 534 Posts
                Thanks for the tipp with the :cdata output filter, works great!

                I needed it to make a flash videogallery controllable with modx (create the xml with getRessources) but I had the Problem, that every textblock that was wrapped in cdata Tags had some whitespace at the beginning...I had a look into the core "core/model/modx/filters/modoutputfilter.class.php" and there was the problem, the whitespace is already in the code, I changed it to:

                                    case 'cdata':
                                        $output= "<![CDATA[{$output}]]>";
                                        break;


                and now the problem is gone...I don’t know how to file a "bug" like this, but if this could be changed in the core, it would be great!

                keep up the good work!

                EDIT: OK, I tried to open a ticket in the bugtracker, hope I did it right...
                  • 22303 MODX Staff
                  • 10,725 Posts
                  This is a feature not a bug, to prevent JS problems when it appears within the CDATA tags. It’s a tag conflict issue. Why is the whitespace a problem? And if it is, you can create your own filter to wrap in CDATA without the whitespace.
                    • 18367
                    • 834 Posts
                    How do I remove the time from this?

                    <pubDate>[[+createdon:strtotime:date=`%a, %d %b %Y %H:%M:%S %z`]]</pubDate>


                    I tried just deleting the %H %M %S but that just gave me a default time for everything.

                    Thanks
                      Content Creator and Copywriter