Convert a string to availability images

  Previous article Next article  

Convert a string to availability images

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.2
  Last updated: 24-02-2016
  Comments: 0

A simple and easy to use availability feature for CMS Made Simple™. A User Defined Tag (UDT) converts a comma seperated string of 0's and 1's into a list of images.

You can use it for i.e. opening hours of a store or an overview of soccer trainings.

  How to use

I will show you an explanation with three rows of images for store openings.

Create a UDT named i.e. "Availability" and with the content:

$stringlist = isset($params['stringlist']) ? $params['stringlist'] : '';

$strings = explode(',' , $stringlist);

foreach ($strings as $string) {
  echo '<img src="uploads/images/img_availability_' . $string . '.jpg" alt="" />';
}

Note: You probably need to change the image path in the code...


Add in the top of your Core::Page template:

{$stringlist1 = "{content block=stringlist1 oneline=true}" label='Availability Morning' scope=global}
{$stringlist2 = "{content block=stringlist2 oneline=true}" label='Availability Afternoon' scope=global}
{$stringlist3 = "{content block=stringlist3 oneline=true}" label='Availability Evening' scope=global}

And in the area where you want the availaility images in a page or another spot in the template:

<h3>Availability</h3>

<h4>Morning</h4>
  {Availability stringlist=$stringlist1}
<h4>Afternoon</h4>
  {Availability stringlist=$stringlist2}
<h4>Evening</h4>
  {Availability stringlist=$stringlist3}

In the image folder I have two images:

  named img_availability_0.jpg

  named img_availability_1.jpg


A2 Webhosting CMS Made Simple

  Working example

I filled the stringlist fields with:
"0,0,1,1,1,1,1"
"0,1,1,1,1,1,1"
"0,0,0,0,1,1,0"

The generated output will be something like:

Availability

Morning

Afternoon

Evening



Show related articles:



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 ]


  0 Comments

No comments yet...

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

Convert a string to availability images

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.2
  Last updated: 24-02-2016
  Comments: 0

A2 Webhosting CMS Made Simple