Template Lite - the faster compiling PHP template engine
Custom Functions
Description
This block function will collect the output it encases and store it in a variable instead of displaying it. The variable can then be modified and manipulated.
Arguments
- name
This is The name of the captured block.
- assign
This is the name of the variable that the captured block will be assigned into.
Example
EXAMPLE
=============================
{ capture assign=variable }
Now is the time to test things out.
{/capture}
{ $variable|upper }
{capture name=testcapture}
Now is the time to test things out.
{/capture}
Description
This function will remove all repeated spaces, new lines, and tabs with a single instance.
Example
TEMPLATE
=============================
{* the following will be all run into one line upon output *}
{ strip}
<A HREF="{ $url }">
<font color="red">This is a test</font>
</A>
{ /strip }
OUTPUT
=============================
<A HREF="http://my.domain.com"><font color="red">This is a test</font></A>
Description
This block function is used to clean up spaces, special characters and formats paragraphs by wrapping at a boundary and indenting lines.
Arguments
- assign(optional)
The template variable the output will be assigned to.
- indent(optional)
The number of chars to indent every line. Default value = 0
- indent_first(optional)
The number of chars to indent the first line. Default value = 0
- indent_char(optional)
The character (or string of chars) to indent with. Default value = single space
- style(optional)
Preset style of email set to 72 characters.
- wrap(optional)
How many characters to wrap each line to. Default value = 80
- wrap_char(optional)
The character (or string of chars) to break each line with. Default value = \n
- wrap_cut(optional)
If true, wrap will break the line at the exact character instead of at a word boundary. Default value = false
- assign(optional)
The template variable the output will be assigned to.
Example
EXAMPLE
=============================
{ textformat wrap=20 }
This is a special test of the 20 wrap.
{ textformat }
OUTPUT
=============================
This is a special te
st of the 20 wrap.
Description
This function is an incremental counter that will increase by the specified amount each time it is called, or not, depending on how it is called.
Arguments
- name (optional)
The name of the counter.
- start (optional)
The number to start counting from. Default is 1.
- skip (optional)
The interval to count by. Default is 1.
- direction (optional)
The direction to count in. Either up
or down
.
- print (optional)
Whether or not to print the value. Default is true.
- assign (optional)
The template variable that the value will be assigned to.
Example
TEMPLATE
=============================
{* initialize the count *}
{counter start=0 skip=2 print=false}
{counter}<br>
{counter}<br>
{counter}<br>
{counter}<br>
OUTPUT
=============================
2<br>
4<br>
6<br>
8<br>
Description
Cycle will alternate between multiple values on each recurring call.
Arguments
- name (optional)
The name of the cycle.
- values
The values to cycle through. This can be either a comma separated list or an array of values.
- print (optional)
Whether to print the value or not. The default is to print the value.
- advance (optional)
Whether to advance to the next value or not. The default is to advance the value.
- delimiter (optional)
The delimiter to use in separating the values in the values
argument. The default is a comma.
- assign (optional)
The template variable that the value will be assigned to.
Example
{ foreach value=value from=$data }
<tr bgcolor="{ cycle values="#eeeeee,#d0d0d0" }">
<td>{ $value[rows] }</td>
</tr>
{ /foreach }
OUTPUT
=============================
<tr bgcolor="#eeeeee">
<td>1</td>
</tr>
<tr bgcolor="#d0d0d0">
<td>2</td>
</tr>
<tr bgcolor="#eeeeee">
<td>3</td>
</tr>
Description
This function call will allow you to interface with ADOdb Lite and execute any database functions.
Arguments
- db_object
This is the database connection object. ($db = ADONewConnection($dsn); // The $db object variable would be passed to the template and used by db_object)
- db_function
This is the ADOdb Lite database function to call. Example: Execute (this will execute a database query)
- db_query (optional)
This is an optional SQL statement that is used by functions like Execute
.
- db_assign
This is the template variable to assign the result data or result object .
- db_errornumber_assign (optional)
This is the template variable to assign the error result number that is generated by the database function call. If the function call executed properly the returned value will be 0.
- db_error_assign (optional)
The template variable to assign the error result message that is generated by the database function call. If the function call executed properly the returned value will be empty.
- db_EOF_assign (optional)
The template variable to assign the End of File flag. This flag is used to determine if the LAST element of a result set has been reached. If the returned value is 0 then there are more elements to retrieve.
Example
TEMPLATE
=============================
{ db_function_call db_object=$db_object db_function="Execute" db_query=$query db_assign="result_object"}
Description
This function call will allow you to interface with ADOdb Lite and execute any database result set functions.
Arguments
- db_object
This is the database connection object. ($db = ADONewConnection($dsn); // The $db object variable would be passed to the template and used by db_object)
- db_function
This is the ADOdb Lite database function to call. Example: Execute (this will execute a database query)
- db_result_object
This is the result object that would have been generated by the
db_function_call
.
- db_assign
This is the template variable to assign the result data.
- db_errornumber_assign (optional)
This is the template variable to assign the error result number that is generated by the database function call. If the function call executed properly the returned value will be 0.
- db_error_assign (optional)
The template variable to assign the error result message that is generated by the database function call. If the function call executed properly the returned value will be empty.
- db_EOF_assign (optional)
The template variable to assign the End of File flag. This flag is used to determine if the LAST element of a result set has been reached. If the returned value is 0 then there are more elements to retrieve.
Example
TEMPLATE
=============================
{ db_function_call db_object=$db_object db_function="Execute" db_query=$query db_assign="result_object" db_EOF_assign="eof"}
{while $eof == 0}
{ db_result_call db_object=$db_object db_function="fields" db_result_object=$result_object db_assign="result" db_EOF_assign="eof"}
Name: {$result.name}<br>
{ db_result_call db_object=$db_object db_function="MoveNext" db_result_object=$result_object db_assign="result" db_EOF_assign="eof"}
{/while}
OUTPUT
=============================
George
Mitchel
Jenny
Description
Debug is now a compiler function and operates in the same manner. For more information view the Debug Compiler Function.
Description
Will insert a checkbox into the template.
Arguments
- name
The name of the checkbox.
- value (optional)
The value for the checkbox.
- checked (optional)
Whether or not the checkbox is checked. Must equal value
to be considered true.
Example
TEMPLATE
=============================
{ html_checkboxes name="test" }
OUTPUT
=============================
<INPUT TYPE="CHECKBOX" NAME="test">
Description
Will insert a checkbox into the template.
Arguments
- name
The name of the hidden variable.
- value (optional)
The value for the hidden variable.
- id (optional)
This attribute assigns a document-wide name to a specific instance of an element. Values for id must be unique within a document. Furthermore, this attribute shares the same name space as the name attribute.
Example
TEMPLATE
=============================
{ html_hidden name="test" value="stuff" }
OUTPUT
=============================
<INPUT TYPE="HIDDEN" NAME="test" VALUE="stuff">
Description
Will insert an image (optionally resized) into the template.
Arguments
- url
The URL of the image.
- width (optional)
The desired width of the image.
- height (optional)
The desired height of the image.
- border (optional)
The desired border width of the image.
- alt (optional)
Alternate text for the image.
- limit (optional)
If set to true, this will cause the image to be resized to the above height and width if the above height and width are smaller than the real height and width.
Example
TEMPLATE
=============================
{ html_image url="http://www.yoursite.com/image.jpg" }
{ html_image url="images/me.gif" alt="A picture of me!" }
{ html_image url="picture.gif" width=500 height=400 }
OUTPUT
=============================
<IMG SRC="http://www.yoursite.com/image.jpg" BORDER="0" ALT="http://www.yoursite.com/image.jpg" WIDTH="174" HEIGHT="350">
<IMG SRC="images.me.gif" BORDER="0" ALT="A picture of me!" WIDTH="200" HEIGHT="400">
<IMG SRC="picture.gif" BORDER="0" ALT="picture.gif" WIDTH="500" HEIGHT="400">
Description
Will insert a text box (or optionally a password box) into the template.
Arguments
- name
The name of the input box.
- value (optional)
The value of the input box.
- size (optional)
The visible size of the input box.
- length (optional)
The maximum length of the input box.
- password (optional)
Whether or not to be a password input box.
Example
TEMPLATE
=============================
{ html_input name="test" }
OUTPUT
=============================
<INPUT TYPE="TEXT" VALUE="" NAME="test">
Description
Will create a list of options for a select
in the HTML template.
Arguments
- options
The array of values used to generate the options from.
- selected (optional)
The default value to be selected.
- name (optional)
The name of the select. If present, the plugin will create the select
in the template as well as the options
.
Example
PHP
=============================
$tpl->assign('cust_options', array(
1001 => 'Joe Schmoe',
1002 => 'Jack Smith',
1003 => 'Jane Johnson',
1004 => 'Charlie Brown'));
$tpl->assign('customer_id', 1001);
TEMPLATE
=============================
<select name=customer_id>
{ html_options options=$cust_options selected=$customer_id }
</select>
OUTPUT
=============================
<select name=customer_id>
<option value="1000">Joe Schmoe</option>
<option value="1001" selected="selected">Jack Smith</option>
<option value="1002">Jane Johnson</option>
<option value="1003">Charlie Brown</option>
</select>
Description
Will insert a radio button into the template.
Arguments
- name
The name of the radio button.
- value (optional)
The value of the radio button.
- checked (optional)
Whether the box is checked or not. Must equal value
to be considered true.
Example
TEMPLATE
=============================
{ html_radios name="test" }
OUTPUT
=============================
<INPUT TYPE="RADIO" NAME="test">
Description
Will create date dropdowns for you. It can insert any or all of year, month, and day into the template.
Arguments
- prefix(optional)
Prefix for the var name. Default = Date_
- time(optional)
The date/time to use. Default = current time in unix timestamp or YYYY-MM-DD format
- start_year(optional)
The first year in the dropdown, either year number, or relative to current year (+/- N). Default = current year
- end_year(optional)
The last year in the dropdown, either year number, or relative to current year (+/- N). Default = same as start_year
- display_days(optional)
Should days be displayed. Default = true
- display_months(optional)
Should months be displayed. Default = true
- display_years(optional)
Should years be displayed. Default = true
- month_format(optional)
The format the month should be in (strftime). Default = %B
- day_format(optional)
The format the day output should be in (sprintf). Default = %02d
- day_value_format(optional)
The format the day value should be in (sprintf). Default = %d
- year_as_text(optional)
Should the year be displayed as text. Default = false
- reverse_years(optional)
Display the years in reverse order. Default = false
- field_array(optional)
If a name is given, the select boxes will be drawn such that the results will be returned to PHP in the form of name[Day], name[Year], name[Month]. Default = null
- day_size(optional)
Size attribute for select tag if given. Default = null
- month_size(optional)
Size attribute for select tag if given. Default = null
- year_size(optional)
Size attribute for select tag if given. Default = null
- all_extra(optional)
Adds extra attributes to all select/input tags if given. Default = null
- day_extra(optional)
Adds extra attributes to select/input tags if given. Default = null
- month_extra(optional)
Adds extra attributes to select/input tags if given. Default = null
- year_extra(optional)
Adds extra attributes to select/input tags if given. Default = null
- field_order(optional)
The order in which to display the fields. Default = MDY
- field_separator(optional)
The string printed between the different fields. Default = \n
- month_value_format(optional)
The strftime format of the month values. Default = %m
- year_empty(optional)
If supplied then the first element of the year's select-box has this value as it's label and "" as it's value. This is useful to make the select-box read "Please select a year" for example. Note that you can use values like "-MM-DD" as time-attribute to indicate an unselected year. Default = null
- month_empty(optional)
If supplied then the first element of the month's select-box has this value as it's label and "" as it's value. . Note that you can use values like "YYYY--DD" as time-attribute to indicate an unselected month. Default = null
- day_empty(optional)
If supplied then the first element of the day's select-box has this value as it's label and "" as it's value. Note that you can use values like "YYYY-MM-" as time-attribute to indicate an unselected day. Default = null
Example
TEMPLATE
=============================
{ html_select_date }
OUTPUT
=============================
<select name="Date_Month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3>March</option>
<option value="4" selected="selected">April</option>
..... cut .....
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="Date_Day">
<option value="1">01</option>
<option value="2" selected="selected>02</option>
..... cut .....
<option value="31">31</option>
</select>
<select name="Date_Year">
<option value="2006" selected="selected">2006</option>
</select>
Description
Will create time dropdowns for you. It can insert any or all of hour, minute, second and meridian into the template.
Arguments
- prefix(optional)
Prefix for the var name. Default = Time_
- time(optional)
The date/time to use. Default = current time in unix timestamp or YYYY-MM-DD format
- display_hours(optional)
Should hours be displayed. Default = true
- display_minutes(optional)
Should minutes be displayed. Default = true
- display_seconds(optional)
Should seconds be displayed. Default = true
- display_meridian(optional)
Should meridian be displayed (am/pm). Default = true
- use_24_hours(optional)
Display as 24 hour clock. Default = true
- minute_interval(optional)
The number interval in minute dropdown. Default = 1
- second_interval(optional)
The number interval in second dropdown. Default = 1
- field_array(optional)
If a name is given, the output values are stored in an array of this name. Default = n/a
- all_extra(optional)
Adds extra attributes to all select/input tags if given. Default = null
- hour_extra(optional)
Adds extra attributes to select/input tags if given. Default = null
- minute_extra(optional)
Adds extra attributes to select/input tags if given. Default = null
- second_extra(optional)
Adds extra attributes to select/input tags if given. Default = null
- meridian_extra(optional)
Adds extra attributes to select/input tags if given. Default = null
Example
TEMPLATE
=============================
{ html_select_time use_24_hours=true }
OUTPUT
=============================
<select name="Time_Hour">
<option value="00">00</option>
<option value="01" selected>01</option>
..... cut .....
<option value="22">22</option>
<option value="23">23</option>
</select>
<select name="Time_Minute">
<option value="00" selected>00</option>
<option value="01">01</option>
..... cut .....
<option value="58">58</option>
<option value="59">59</option>
</select>
<select name="Time_Second">
<option value="00" selected>00</option>
<option value="01">01</option>
..... cut .....
<option value="58">58</option>
<option value="59">59</option>
</select>
<select name="Time_Meridian">
<option value="am" selected>AM</option>
<option value="pm">PM</option>
</select>
Description
Will dump an array of data into an HTML table. The cols attribute determines how many columns will be in the table. The table_attr, tr_attr and td_attr values determine the attributes given to the table, tr and td tags. If tr_attr or td_attr are arrays, they will be cycled through. trailpad is the value put into the trailing cells on the last table row if there are any present..
Arguments
- loop
The array of data to loop through.
- cols(optional)
The number of columns in the table. if the cols-attribute is empty, but rows are given, then the number of cols is computed by the number of rows and the number of elements to display to be just enough cols to display all elements. If both, rows and cols, are omitted cols defaults to 3. Default = 3
- rows(optional)
The number of rows in the table. if the rows-attribute is empty, but cols are given, then the number of rows is computed by the number of cols and the number of elements to display to be just enough rows to display all elements.
- inner(optional)
The direction of consecutive elements in the loop-array to be rendered. cols means elements are displayed col-by-col. rows means elements are displayed row-by-row. Default = cols
- table_attr(optional)
The attributes for table tag. Default = border="1"
- tr_attr(optional)
The attributes for tr tag (arrays are cycled).
- td_attr(optional)
The attributes for td tag (arrays are cycled).
- trailpad(optional)
The value to pad the trailing cells on last row with (if any). Default =
- hdir(optional)
The direction of each row to be rendered. possible values: right (left-to-right), and left (right-to-left). Default = right
- vdir(optional)
The direction of each column to be rendered. possible values: down (top-to-bottom), up (bottom-to-top). Default = down
Example
PHP
=============================
<?php
require('class.template.php');
$template_object = new Template_Lite;
$template_object->assign('data',array(1,2,3,4,5,6,7,8,9));
$template_object->assign('tr',array('bgcolor="#eeeeee"','bgcolor="#dddddd"'));
$template_object->display('index.tpl');
?>
TEMPLATE
=============================
{ html_table loop=$data }
{ html_table loop=$data cols=4 table_attr='border="0"' }
{ html_table loop=$data cols=4 tr_attr=$tr }
OUTPUT
=============================
<table border="1">
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
</table>
<table border="0">
<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr><td>5</td><td>6</td><td>7</td><td>8</td></tr>
<tr><td>9</td><td> </td><td> </td><td> </td></tr>
</table>
<table border="1">
<tr bgcolor="#eeeeee"><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr bgcolor="#dddddd"><td>5</td><td>6</td><td>7</td><td>8</td></tr>
<tr bgcolor="#eeeeee"><td>9</td><td> </td><td> </td><td> </td></tr>
</table>
Description
Will insert a textbox into the template.
Arguments
- name
The name of the textbox.
- rows (optional)
The number of rows in the textbox.
- columns (optional)
The number of columns in the textbox.
- value (optional)
The value of the textbox.
Example
TEMPLATE
=============================
{ html_textbox name="test" rows="4" columns="60" }
OUTPUT
=============================
<TEXTAREA NAME="test" ROWS="4" COLS="60"></TEXTAREA>
Description
Will search an array for a matching value and return the set returnvalue if a match is found.
Arguments
- array
The array to search for the match.
- match
The value to match inside the array
- returnvalue
This is the value to be returned if a match is found.
Example
TEMPLATE
=============================
<input type="checkbox" name="test" value="1" { in_array array=$atribname[$i] match=$atrib returnvalue="CHECKED" }>
OUTPUT
=============================
<input type="checkbox" name="test" value="1" CHECKED>
Description
Will insert a mailto: link and optionally encodes them into the template. Encoding e-mails makes it more difficult for web spiders to lift e-mail addresses off of your site.
Arguments
- address
The e-mail address.
- text (optional)
The text to display, default is the e-mail address.
- encode (optional)
How to encode the e-mail. Can be none, hex, javascript or javascript_charcode. Default = none
- cc (optional)
The e-mail addresses to carbon copy. Separate entries by a comma.
- bcc (optional)
The e-mail addresses to blind carbon copy. Separate entries by a comma.
- subject (optional)
The e-mail subject.
- newsgroups (optional)
The newsgroups to send post. Separate entries by a comma.
- followupto (optional)
The addresses to follow up to. Separate entries by a comma.
- extra (optional)
Any extra information you want passed to the link, such as style sheet classes.
Example
TEMPLATE
=============================
{ mailto address="me@example.com" }
{ mailto address="me@example.com" text="send me some mail" }
OUTPUT
=============================
<a href="mailto:me@example.com" >me@example.com</a>
<a href="mailto:me@example.com" >send me some mail</a>
Description
Will allow the template designer to do math equations in the template. Any numeric template variables may be used in the equations, and the result is printed in place of the tag. The variables used in the equation are passed as parameters, which can be template variables or static values. +, -, /, *, abs, ceil, cos, exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt, srans and tan are all valid operators. Check the PHP documentation for further information on these math functions.
If you supply the special "assign" attribute, the output of the math function will be assigned to this template variable instead of being output to the template.
Arguments
- equation
The equation to execute.
- format (optional)
The format of the result (sprintf).
- var
The equation variable value.
- assign (optional)
The template variable the output will be assigned.
- [var ...]
The equation variable value.
Example
TEMPLATE
=============================
{ math equation="(( x + y ) / z )" x=2 y=10 z=2 }
{ math equation="x + y" x=4.4444 y=5.0000 format="%.2f" }
OUTPUT
=============================
6
9.44
Description
{popup_init} must be called once at the top of any page you plan on using the {popup} function. {popup} is an integration of overLib, a library used for popup windows. These are used for context sensitive information, such as help windows or tooltips.
overLib was written by Erik Bosrup, and the homepage/download is located at http://www.bosrup.com/web/overlib/.
Example
TEMPLATE
=============================
<head>
{* popup_init must be called once at the top of the page *}
{popup_init src="javascripts/overlib.js"}
</head>
Description
Will allow the template designer to create javascript popup windows. {popup_init} MUST be called first for this to work.
Arguments
- text
The text/html to display in the popup window.
- trigger (optional)
What is used to trigger the popup window. Can be one of onMouseOver or onClick. Default = onMouseOver
- sticky (optional)
Makes the popup stick around until closed. Default = false
- caption (optional)
Sets the caption to title.
- fgcolor (optional)
The color of the inside of the popup box.
- bgcolor (optional)
The color of the border of the popup box.
- textcolor (optional)
The color of the text inside the box.
- capcolor (optional)
The color of the box's caption.
- closecolor (optional)
The color of the close text.
- textfont (optional)
The font to be used by the main text.
- captionfont (optional)
The font of the caption.
- closefont (optional)
The font for the "Close" text.
- textsize (optional)
The size of the main text's font.
- captionsize (optional)
The size of the caption's font.
- closesize (optional)
The size of the "Close" text's font.
- width (optional)
The width of the box.
- height (optional)
The height of the box.
- left (optional)
Makes the popups go to the left of the mouse. Default = false
- right (optional)
Makes the popups go to the right of the mouse. Default = false
- center (optional)
Makes the popups go to the center of the mouse. Default = false
- above (optional)
Makes the popups go above the mouse. NOTE: only possible when height has been set. Default = false
- below (optional)
Makes the popups go below the mouse. Default = false
- border (optional)
Makes the border of the popups thicker or thinner.
- offsetx (optional)
How far away from the pointer the popup will show up, horizontally.
- offsety (optional)
How far away from the pointer the popup will show up, vertically.
- fgbackground (optional)
Defines a picture to use instead of color for the inside of the popup. Use the URL to the image.
- bgbackground (optional)
Defines a picture to use instead of color for the border of the popup. NOTE: You will want to set bgcolor to "" or the color will show as well. NOTE: When having a Close link, Netscape will re-render the table cells, making things look incorrect. Use the URL to the image.
- closetext (optional)
Changes the "Close" text to something different.
- noclose (optional)
Does not display the "Close" text on stickies with a caption.
- status (optional)
Sets the text in the browsers status bar.
- autostatus (optional)
Sets the status bar's text to the popup's text. NOTE: overrides status setting.
- autostatuscap (optional)
Sets the status bar's text to the caption's text. NOTE: overrides status and autostatus settings.
- inarray (optional)
Sets overLib to read text from this index in the ol_text array, located in overlib.js. This parameter can be used instead of text.
- caparray (optional)
Sets overLib to read the caption from this index in the ol_caps array.
- capicon (optional)
Displays the image given before the popup caption. Use a URL to the image.
- snapx (optional)
Snaps the popup to an even position in a horizontal grid.
- snapy (optional)
Snaps the popup to an even position in a vertical grid.
- fixx (optional)
Locks the popups horizontal position Note: overrides all other horizontal placement.
- fixy (optional)
Locks the popups vertical position Note: overrides all other vertical placement.
- background (optional)
Sets image to be used instead of table box background. Use a URL to the image.
- padx (optional)
Pads the background image with horizontal whitespace for text placement. Note: this is a two parameter command.
- pady (optional)
Pads the background image with vertical whitespace for text placement. Note: this is a two parameter command.
- fullhtml (optional)
Allows you to control the html over a background picture completely. The html code is expected in the "text" attribute.
- frame (optional)
Controls popups in a different frame. See the overlib page for more info on this function.
- timeout (optional)
Calls the specified javascript function and takes the return value as the text that should be displayed in the popup window.
- delay (optional)
Makes that popup behave like a tooltip. It will popup only after this delay in milliseconds.
- hauto (optional)
Automatically determine if the popup should be to the left or right of the mouse.
- vauto (optional)
Automatically determine if the popup should be above or below the mouse.
Example
TEMPLATE
=============================
{* popup_init must be called once at the top of the page *}
{popup_init src="/javascripts/overlib.js"}
{* create a link with a popup window when you move your mouse over *}
<a href="mypage.html" {popup text="This link takes you to my page!"}>mypage</a>
{* you can use html, links, etc in your popup text *}
<a href="mypage.html" {popup sticky=true caption="mypage contents"
text="<ul><li>links</li><li>pages</li><li>images</li></ul>"
snapx=10 snapy=10}>mypage</a>
Home