MENU

A XML or RSS-feed reader with plain Smarty

  Previous article Next article  

Create your own XML or RSS-feed reader with plain Smarty, there are no external modules or plug-ins needed!

  How to use

Page

Create a new content page and set WYSIWYG off.
Copy the following code in the content of the page. Note, this template is just an example: with the parameters below you can change it to your liking.

In the first line you can add the URL of the feed you want to display at your website.

{$xml = simplexml_load_file('https://www.cmscanbesimple.org/feeds/blog.rss')}

{if !empty($xml)}
  <h3>{$xml->channel->title}</h3>
  <h4>{$xml->channel->description}</h4>
  <p>Generator: {$xml->channel->generator}<br />
  URL: {$xml->channel->link}<br />
  Copyright: {$xml->channel->copyright}</p>

  {$cnt = 0}
  {foreach $xml->channel->item as $item}
    <h4><a href="{$item->link}">{$item->title}</a></h4>
    <p>{$item->pubDate|date_format:'%e %B %Y'}<br />
    {$item->author}: {$item->description} <a href="{$item->guid}">Read more</a></p>  
    {$cnt = $cnt + 1}
    {if $cnt == 2}{break}{/if}
  {/foreach}
{else}
  <p>No feed found...</p>
{/if}

The number "2" in the $cnt line above, is the number of feed items that will be shown at your page.

Available parameters

Channel section

{$xml->channel->title}
{$xml->channel->description}
{$xml->channel->generator}
{$xml->channel->link}
{$xml->channel->webMaster}
{$xml->channel->managingEditor}
{$xml->channel->copyright}

{$xml->channel->image->link}
{$xml->channel->image->url}
{$xml->channel->image->width}
{$xml->channel->image->height}
{$xml->channel->image->title}

Item section

{$item->link}
{$item->title}
{$item->pubDate}
{$item->author}
{$item->description}
{$item->guid}

{$item->enclosure['url']}
{$item->enclosure['length']}
{$item->enclosure['type']}

Options

Channel image example

{if isset($xml->channel->image->url)}
  <a href="{$xml->channel->image->link}">
    <img src="{$xml->channel->image->url}" width="{$xml->channel->image->width}" height="{$xml->channel->image->height}" alt="{$xml->channel->image->title}" />
  </a>
{/if}

Item image enclosure example

{if isset($item->enclosure['url'])}
  <img src="{$item->enclosure['url']}" alt="{$item->title}" />
{/if}

Permissive Smarty

In the latest Smarty releases due to security settings PHP functions aren't available by default... If you do want to use PHP functions, you have to enable them by adding this line to your CMSMS config.php file:

$config['permissive_smarty'] = 1;

This config variable loosens some of the security configuration for Smarty templates. Particularly enabling this option allows the use of any PHP function as a Smarty plugin. You better not use this option if you are allowing content to be submitted for display on your website from untrusted sources!
If the feed reader works without this line, you better not add it!

  Working example


The next example is the output of the template described above and displays the CMS Can Be Simple blog feed:

CMS Made Simple

CMS Made Simple Announcements

Generator: CMS Made Simple
URL: https:https://www.cmsmadesimple.org/blog
CMSMS

CMS Made Simple 2.2.19 - Selkirk

28 November 2023
Today we are delighted to announce the release of CMS Made Simple v2.2.19 - Selkirk. v2.2.19 - Selkirk is an incremental bug fix and stability release. For further detailed information, please see the changelog where there is a full list of fixes and improvements. As per the Dev Team's official support policy, the only versions of CMSMS currently supported are now v2.2.18 and v2.2.19.... Read more

v2.2.17 - Iqaluit Release Announcement

19 June 2023
http://www.cmsmadesimple.org/downloads/cmsms  We are pleased to announce the release of CMS Made Simple v2.2.17 - Iqaluit, an incremental bug fix, security, and stability release. Read more




Buy Me A Coffee


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  7 Comments

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

A XML or RSS-feed reader with plain Smarty

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.3.1
  Last updated: 25-03-2021
  Comments: 7
  http://cms.ms/mMW2


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!