3 # Copyright (C) 2005 Jason Woofenden PUBLIC DOMAIN
6 # This file demonstrates, documents and tests the template system (along with
9 # First we'll need the functions in wfpl/template.php:
10 require_once('code/wfpl/template.php');
11 # Always use the exact require_once statement above to get access to these
12 # functions. You should have in each directory of your projects a copy of wfpl
13 # or a symbolic link to it. This allows there to be different versions of wfpl
14 # without changing the php for the site.
16 # Now grab the template (you might want to take a look at this file)
17 tem_load('tem_test.php.html');
18 # This creates a template object to store all sorts of things, and then reads
19 # in the template file and scans through it for sub-templates. Sub templates
20 # are parts of the template that may appear any number of times in the output
21 # (even zero times) such as a table row meant to hold a database record.
23 # This is probably not the best example, but this template contains tables for
24 # login, and for displaying some fake database content. For this silly example
25 # I decide which I'm going to display by checking if the user has submitted a
27 if(!isset($_REQUEST['user'])) {
28 # tem_set() gives a key/value pair to template.php. When the template is
29 # output (or sub-templates are run with tem_sub) any occurences of ~user~
30 # will be replaced with 'bert'.
31 tem_set('user', 'bert');
33 # The template file contains a sub-template called 'login'. By default,
34 # sub-templates do not display at all. They display once for each time you
38 # This runs the template and prints the output. Running the template is
39 # simply replacing all ~key~ tags with the associated value. The values are
40 # set with tem_set() and tem_sub().
46 # Below is an example of using a sub-sub-template many times
48 # first set some values to be displayed in the row:
49 tem_set('foo', '*&^@$<>"');
50 tem_set('bar', 'one*&^@$<>"');
52 # Now run the row. This runs the sub-template for the row, and appends the data
53 # for the 'foobar_row' entry in the main key/value list.
54 tem_sub('foobar_row');
56 # and a couple more times:
57 tem_set('foo', '"""""****"""""');
58 tem_set('bar', 'two*&^"');
59 tem_sub('foobar_row');
60 tem_set('foo', '<<<<<<&&&&&&&&>>>>>');
61 tem_set('bar', 'threeeeeeee*&^@$<>"eeeeeeeeeeee');
62 tem_sub('foobar_row');
64 # Now we have a 'foobar_row' in the main keyval array with three rows of html in it.
66 # in the template foobar_row is within a bigger sub-template called
67 # 'foobar_table'. The only reason for this is so that we can have that table
68 # not display at all when we're displaying the login. This is a silly use of
69 # the templates, but I wanted to demonstrate and test a simple use of a
70 # sub-template within a sub-template.
71 tem_sub('foobar_table');
74 # Now run the main template (the body of the template file)