A XML or RSS-feed reader with plain Smarty

  Previous article Next article  

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: 17-10-2017
  Comments: 5

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('http://feeds.feedburner.com/cmsmadesimple/blog')}

{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']}

A2 Webhosting CMS Made Simple

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 official CMS Made Simple™ RSS News feed:

CMS Made Simple

CMS Made Simple Announcements

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

Can your customers help in the vote?

4 October 2017

Last month, we were delighted to announce that, thanks to you, our excellent user base, we've been nominated in the CMS Critic awards in two categories! The vote is now underway! We know that many of you have already voted and that's fantastic.

Read more

Thanks to you we did it!

12 September 2017

Thanks to you, our excellent user base and your customers we have been nominated in the CMS Critic awards in not one but two categories! This wouldn’t have been possible without your excellent response to our request for help. The dev team would like to express its gratitude to all of you.

Read more


A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  5 Comments

CMS Made Simple 2.2.3.1 - Tutorials, tips and tricks - CMSMS 2.2.3.1

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: 17-10-2017
  Comments: 5

A2 Webhosting CMS Made Simple