MENU

Share data between websites: the cache_remote_file tag

  Previous article Next article  

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.

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 174 websites in the showcase.



  Show related articles:


  Comment Form

Click here to open the form


  2 Comments

CMS Made Simple - Tutorials, tips and tricks - CMSMS

Share data between websites: the cache_remote_file tag

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.7
  Last updated: 23-06-2018
  Comments: 2
  http://cms.ms/7S86

Advertisement



Ads help me to help you! Thanks!

Ads help me to help you! Thanks!

Ads help me to help you! Thanks!