forked from unusorin/php-xtemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex2.php
executable file
·72 lines (56 loc) · 1.52 KB
/
ex2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* example 2
* demonstrates multiple level dynamic blocks
*
* @package XTemplate_Examples
* @author Barnabas Debreceni [[email protected]]
* @copyright Barnabas Debreceni 2000-2001
* @author Jeremy Coates [[email protected]]
* @copyright Jeremy Coates 2002-2007
* @see license.txt LGPL / BSD license
* @link $HeadURL: https://xtpl.svn.sourceforge.net/svnroot/xtpl/trunk/ex2.php $
* @version $Id: ex2.php 16 2007-01-11 03:02:49Z cocomp $
*/
include_once('./xtemplate.class.php');
$xtpl = new XTemplate('ex2.xtpl');
/**
* you can reference to array keys in the template file the following way:
* {DATA.ID} or {DATA.NAME}
* say we have an array from a mysql query with the following fields: ID, NAME, AGE
*/
$rows = array();
// add some data
$rows[1]=array('ID'=>'38',
'NAME'=>'cocomp',
'AGE'=>'33'
);
// add some data
$rows[2]=array('ID'=>'27',
'NAME'=>'linkhogthrob',
'AGE'=>'34'
);
// add some data
$rows[3]=array('ID'=>'56',
'NAME'=>'pingu',
'AGE'=>'23'
);
$rowsize = count($rows);
for ($i = 1; $i <= $rowsize; $i++) {
// assign array data
$xtpl->assign('DATA', $rows[$i]);
$xtpl->assign('ROW_NR', $i);
// parse a row
$xtpl->parse('main.table.row');
// another way to do it would be:
/*
$xtpl->insert_loop('main.table.row', array('DATA'=>$rows[$i],
'ROW_NR'=>$i
));
*/
}
// parse the table
$xtpl->parse('main.table');
$xtpl->parse('main');
$xtpl->out('main');
?>