This article describes how to modify the getFeed extra for MODX to display reviews from a Trustpilot RSS feed on your website.
One of my clients uses the Trustpilot customer review service and wanted to display the reviews they have received on their website. In order to display the reviews in a format to match the client's branding it was decided to use the Trustpilot RSS feed and style it to suit.
Customised Trustpilot RSS Reader for MODX
The getFeed extra by Shaun McCormick (splittingred) would be perfect to read the Trustpilot feed but it contains fields with semi colons that getFeed cannot access.
See: 01 trustpilot-rss-example.xml
Luckily Jiri Pavlicek has already experienced this issue and provided a fix over on GitHub by making a small change to the original.
To ensure the changes are not overwritten if the original getFeed Snippet is updated via Package Manager I created a duplicate called it getFeedPlus. There are no additional properties so it is called in exactly the same way as getFeed.
See: 02 getFeedPlus-call.txt and 03 snippet-getFeedPlus.php
Styling the output
A template Chunk is required to handle the output of the feed items.
See: 04 chunk-trustpilot.tpl
Tidying the pubDate
The Publication Date is a little untidy as it includes the timestamp and timezone eg.
Fri, 01 Aug 2014 08:14:36 GMT
An easy way to tidy this is to trim the end off the string by applying an Output Modifier to the pubdate placeholder in the template:
[[+pubdate:limit=`16`]]
This outputs the Publication Date in a more friendly format:
Fri, 01 Aug 2014
This outputs the Publication Date in a more friendly format:
Fri, 01 Aug 2014
Displaying the Star rating
The review template chunk-trustpilot.tpl calls the trustpilot-stars snippet which calculates how many stars were awarded for by the current review and outputs a block of html (chunk-trustpilot-star.tpl) for each star awarded.
See: 05 snippet-trustpilot-stars.php and 06 chunk-trustpilot-star.tpl
The Result
The custom layout integrates perfectly into the client's website and doesn't require the extra Javascript call that is required by the TrustBox Widget provided by Trustpilot.