Knowledgebase : PHP Templating Reference > Common PHP Template Functions
   

Description:

This PHP function will neatly print the length of a movie in minutes and seconds.

Common Location:

/cms_admin/phptemplate/<templatefolder>/functions/standard.tpl

Usage:

<?php echo Display_MovieLength(127) ?>

Arguments

1) The length of the movie in seconds.

Output

2 minute(s) 7 second(s)

 

Description:

This will convert the path to a file to a full qualified URL. If the path passed along is already a full qualified URL, this function will return its output.

Common Location:

/cms_admin/phptemplate/<templatefolder>/functions/standard.tpl

Usage:

<?= full_url("/path/to/file.html"); ?>

<?= full_url("http://yourdomain.com/path/to/file.html"); ?>

Arguments

1) The path to the file / location.

Output

If this code is being run on yourdomain.com, the output of this function will be:

http://yourdomain.com/path/to/file.html

http://yourdomain.com/path/to/file.html

If this code is being run on yourdomain2.com, the output listed above will be:

http://yourdomain2.com/path/to/file.html

http://yourdomain.com/path/to/file.html

This is because if there no absolute URL specified, full_url() will substitute the existing HTTP_HOST name in its place.

 

Description:

Returns either true or false based on whether or not a key in an array is the last element.

Common Location:

/cms_admin/phptemplate/<templatefolder>/functions/standard.tpl

Usage:

<?php
  $names = ["Anne", "Beth", "Carol", "Denise"];

  foreach($names as $key => $name)
  {
    echo $name;
    if (!last($sets, $key)) echo ", ";
  }

?>

In this case, a comma will be printed after each name, unless the element is the last name.

Arguments

1) The full array

2) The key of the array.

Output

Anne, Beth, Carol, Denise

Description:

This is the standard function used to load a subtemplate from a regular CMS template. It differs from a regular PHP call such as include by:

1) Variables that are declared within the existing template won't get assigned in the subtemplate UNLESS they are explicitly passed along.

2) Global variables (viewed by adding debug=1 to the members/template URL) declared by the CMS engine are available within the subtemplate automatically.

Common Location:

/cms_admin/phptemplate/<templatefolder>/functions/standard.tpl

Usage:

<?php LoadTemplate("template_sections/template.tpl"); ?>

<?php LoadTemplate("template_sections/template.tpl", ["varname" => 1]); ?>

Arguments

1) The first argument is the path to the template that should be loaded.

2) The second argument is a list of variables that should be included into the global scope once this template is included.

Within the second example above, an array is passed along with ["varname" => 1]. Within template.tpl, a variable name called $varname will be available, and its value is set to 1.

Description:

This will print an image for a specific set that is passed to it.

Common Location:

/cms_admin/phptemplate/<templatefolder>/functions/standard.tpl

Usage:

<?php foreach ($tags as $tag) { ?>

<?php StdCatImage(array("category" => $tag, "usepriority" => "34", "alt" => "", "class" => "update_thumb thumbs")); ?>

<?php } ?>

Arguments

There is only one argument that is passed to StdCatImage(), however, it is an associative array with the following possible elements:

category: This is an array containing all of the metadata for a category (which comes from the CMS)
usepriority: These are a list of thumbnail slots that the function should look for and use, separated by commas.
If multiple priorities are listed, use the first priority within the image, and use subsequent priorities as rollover images.
alt: This is the alt tag that should show on the image.
class: These are the CSS classes that will apply to the image.

Output

Here's an example of the output this function will do:

<img src="/members_php/content//contentthumbs/7-cat.jpg" id="set-target-43" alt="" class="update_thumb thumbs stdimage" src0="/members_php/content//contentthumbs/7-cat.jpg" cnt="1" v="0">

 

Description:

This will print an image for a specific set that is passed to it.

Common Location:

/cms_admin/phptemplate/<templatefolder>/functions/standard.tpl

Usage:

<?php foreach ($sets as $set) { ?>

<?php StdImage(array("set" => $set, "usepriority" => "14,20,21,22,23,24,25", "alt" => "", "class" => "update_thumb thumbs")); ?>

<?php } ?>

Arguments

There is only one argument that is passed to StdImage(), however, it is an associative array with the following possible elements:

set: This is an array containing all of the metadata for a set (which comes from the CMS)
usepriority: These are a list of thumbnail slots that the function should look for and use, separated by commas.
If multiple priorities are listed, use the first priority within the image, and use subsequent priorities as rollover images.

In the above example:
14,20,21,22,23,24,25

The system will show a priority 14 thumbnail, but when the user mouses over the thumbnail, the images will cycle through a priority 20,21,22,23,24 and 25 image before returning to a priority 14 image.

alt: This is the alt tag that should show on the image.
class: These are the CSS classes that will apply to the image.

Output

Here's an example of the output this function will do:

<img id="set-target-133" alt="" class="update_thumb thumbs stdimage" src="/members_php/content//contentthumbs/760.jpg" src0="/members_php/content//contentthumbs/760.jpg" src1="/members_php/content//contentthumbs/9275.jpg" src2="/members_php/content//contentthumbs/9276.jpg" src3="/members_php/content//contentthumbs/9277.jpg" src4="/members_php/content//contentthumbs/9280.jpg" src5="/members_php/content//contentthumbs/9279.jpg" src6="/members_php/content//contentthumbs/9278.jpg" cnt="7" v="0" height="170" width="235">

The standard CMS template has JavaScript functionality that takes all image tags with the class "stdimage", and rotates through src0, src1... src6 when the user mouses over the image.