e4e809882b8671529acf44933c0b6945c3fbb806
[yatt.git] / php / example.php
1 <?
2
3 require_once('YATT.class.php');
4
5 $n = new YATT();
6
7 $n->load("example.yatt");
8
9 # set a variable
10 $n->set('CRACK', 'eat me');
11
12 # or like this
13 $n->set(array("FOO" => "something else", "BAR" => "barorific!"));
14
15 # Variable substitution is recursive, see how this works in the template
16 $n->set('FNORK', 'baz');
17 $n->set('CORK_baz', 'shout off and die');
18
19 # Parse a single block of text
20 $n->parse('faz.test');
21
22 # Maybe build a table
23 foreach (array("ONE", "TWO", "THREE") as $value) {
24         $n->set('ROW_NAME', $value);
25         $n->parse('faz.table.row');
26 }
27 $n->parse('faz.table');
28
29 # Comment this out and look at the output.
30 # Notice that everything *but* what is in faz is displayed.
31 # Only nodes that you parse() actually display things.
32 $n->parse('faz');
33
34 # print the output for everything.
35 # You could also tell it where to start, like output('faz.table')
36 # to only print out stuff from table.
37 print "--------------------------------------------------------------\n";
38 print "Output of the template:\n";
39 print "--------------------------------------------------------------\n";
40 print $n->output();
41
42 # If there were any errors, print them out
43 # You should probably check this *before* you print out the page
44 # because these errors will likely cause the page not to be
45 # built correctly. It is done this way so that you only have to
46 # check once, and so you can do something cool with the errors
47 # instead of die().
48 if (($e = $n->get_errors())) {
49     print "--------------------------------------------------------------\n";
50     print "errors:\n";
51     print "--------------------------------------------------------------\n";
52
53     print_r($e);
54 }
55
56 ?>