toastnz / xmlfeed
Silverstripe simple XML feed module
Installs: 63
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 1
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- composer/installers: *
- silverstripe/cms: ^4.3 || ^5.0
- silverstripe/framework: ^4.3 || ^5.0
README
Helper functions to retrieve external XML feed, cache and render into templates.
Requirements
- silverstripe/cms ^4.3.x
- silverstripe/framework ^4.3.x
Installation
composer require toastnz/xmlfeed
Configuration
Configure the default Cache Lifetime or default feed URL:
Toast\XMLFeed\Feed: CacheLifetime: 3600 URL: "https://external.feed.url/feed.xml"
Usage
use Toast\XMLFeed; $feed = Feed::get($url = null, $xmlPath = null, $cacheLifetime = 300, $asArray = false, $flushCache = false);
By default an ArrayList will be returned, which can be rendered directly into a template.
Note: you must check the raw contents of the XML feed to identify fields names.
Example
XML:
<RSS> <Items> <Item> <Headline>Sed in viverra dui. Nullam vel congue massa.</Headline> <Summary>Ut id nisi vitae massa consectetur dictum quis sed sapien. At euismod turpis</Summary> </Item> <Item> <Headline>Aliquam dictum finibus magna</Headline> <Summary>Cras mattis non elit sit amet vulputate. Nunc at metus sed sapien eros.</Summary> </Item> </Items> </RSS>
PHP:
use Toast\XMLFeed; ... class PageController extends ContentController { public function getNewsFeed() { return Feed::get('https://newswebsite.url/news-feed.xml', 'RSS.Items'); } }
Template:
<% loop $NewsFeed %> <h1>$Headline.XML</h1> <p>$Summary.XML</p> <% end_loop %>