MENU

Convert a string to availability images

  Previous article Next article  

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

  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




Advertisement


Ads help me to help you! Thanks!

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


  Show related articles:


  Comment Form

Click here to open the form


  0 Comments

No comments yet...

CMS Made Simple - Tutorials, tips and tricks - CMSMS

Convert a string to availability images

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.12
  Last updated: 23-06-2018
  Comments: 0
  http://cms.ms/Lvj2

Advertisement


Ads help me to help you! Thanks!

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

Advertisement


Ads help me to help you! Thanks!

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