Share data between websites: the cache_remote_file tag

  Previous article Next article  

Share data between websites: the cache_remote_file tag

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.6
  Last updated: 07-02-2017
  Comments: 0

Our community website is built out of multiple CMS Made Simple™ websites. Some content is the same at all websites, i.e. analytics code, global navigation code, sponsors, etc. When something changes I didn't want to do it multiple times. Call me lazy, or call me practical... It was a problem that needed a custom answer, because the available (PHP) options weren't working when the master website was offline for a while... It wasn't fail proof. The content needed to be stored at the website: caching!

Lots of scenarios passed by during the development of the Cache Remote File tag. But at the end it worked like I expected it to be! The plugin tag reads content from the source website and caches it for a adjustable time. When that time has elapsed, it checks if the source content is available. If so, create a new and possibly updated cache file. If not, don't touch the content and try again later.

I use it for:

  • analytics code
  • cookie law information text
  • showing CGBlog post from one site to another
  • display a progress bar from one site at another one
  • etc.

  How to use

Make the information available at the source website, so it can be read by the other website(s). We do this by creating a dynamic "file", in fact it is a page without template/styling.

Therefor create a new Core::Page template with in the content only:

{content}

Now create a new page and attach it to the new blank template. Set the page not visible in navigation.

What ever you put in this page (in HTML) can be read and displayed/processed at another website.


A2 Webhosting CMS Made Simple

At the other website(s) you can read and show or process the content by adding in a page or template:

{cache_remote_file url='http://www.website.com/index.php?page=some-alias'}
{cache_remote_file url='http://www.website.com/index.php?page=some-alias' time='0.5'}
{$value = "{cache_remote_file url='http://www.website.com/index.php?page=value' time='2'}"}

  Working example

Move a value (number) to another site

At WeLoveCMSMS.com there are lots of awesome CMS Made Simple-powered websites showcased!
But how many are there???

The website is using the CGBlog module. I created a new summary template named "itemscount" and the content only:

{$items|@count}

In a hidden page I call this module template, like:

{CGBlog summarytemplate='itemscount'}

Now I read this page here in this article with the cache_remote_file tag. Note: don't use pretty URLs in the tag!

{cache_remote_file url='https://welovecmsms.com/index.php?page=itemscount'}

There are 132 websites in the showcase.


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 ]

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

Share data between websites: the cache_remote_file tag

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.6
  Last updated: 07-02-2017
  Comments: 0

A2 Webhosting CMS Made Simple