Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SilverStripe XML Feed helper

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 %>

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages