The Spry toolset in the latest versions of Dreamweaver are a great set of features, especially the Spry Dataset for integrating xml files such as RSS data feeds. Customisation of certain functionality however, I’ve found tricky to implement at times. Here’s a few Spry tips that I’ve found useful when integrating xml data in websites.
One such seemingly simple task is being able to limit the number of rows displayed in a Spry repeat region from a Spry XML dataset. I found the below solution hidden in the Adobe Spry documentation. To limit the rows from an xml feed, locate the Spry dataset variable e.g:
var ds1 = new Spry.Data.XMLDataSet("feed.xml", "rss/item");
Then add [position() < X] to the xml node element, where X is the number of rows you want to display. For example to limit the rows to 10, use the following:
var ds1 = new Spry.Data.XMLDataSet("feed.xml", "rss/item[position() < 10]");
Limiting the number of characters displayed in a field is another useful function but there's no in-built option for this in the Spry parameters. I found something similar buried somewhere in the Adobe forums, you can use a JavaScript function to limit the amount of characters in any row or field such as a headline or description field.
Firstly add the function below in the head tag:
Where '0' is the character position to start trimming and '100' is how many characters you want to limit the field by. Next, replace the field name in the code generated by the Spry xml dataset to reference the character limiting function. For example the line:
{description}
should become:
{function::restrictChars}
Adobe prevents using cross-domain xml files for security reasons, to protect any potential malicious code from finding it's way into your site. There's a number of reasons you may need to use external feeds, for example if you have multiple domains with data on the sites drawn from a single source.
I initially purchased an extension which I thought would do the trick but I had the security problems enabling the external feed to display in anything but the Chrome browser. Then I found this cross domain solution (for PHP) - full credit to Andy at the Pandahaus for this one.
Simply paste the code block from the link above into a new php file and reference the file from the main Spry dataset definition, i.e:
var ds1 = new Spry.Data.XMLDataSet("feed.php", "rss/item");
Cheers for the code Andy, I have a few sites with external feeds now that are using your cURL technique
Thank you for the mention 🙂