Here I'll show you an simple example holding many basic features
First we write the PHP script
<?php //define two custon function, the first //returns a simple text //the second one get one parameter // and returns it. function foo() { return("text from foo"); } function foop($text) { return("my parameter:".$text); } require_once('sptpl.php'); require_once('sptpl.inc'); require_once('sptpl_db.php'); $t=new sptpl(); //Load the configuration file $t->LoadTemplate('test1.xml'); $t->SetVar("name","George"); $t->SetVar("MyName","Sam"); //Here the example how to set an array $bar['foo']='Index foo'; $t->SetVar("bar",$bar); $t->run("test1.txt"); ?> |
Second step, write the configuration file test1.xml
<?xml version='1.0' ?>
<template> <template> <!-- Define the const1 with value 1 and const2 with value 2 --> <constant name='const1' value = '1'/> <constant name='const2' value = '2'/> <report> <!-- Set the welcome message --> <beginreport> Hi My second test </beginreport> <!-- The open page will be printed on the top of all page --> <OpenPage> Page header. </OpenPage> <!-- In the following row I print the contents of the variable $name and $MyName that was set by the PHP script --> <row id='pippo'> Hello {$name}, my name is {$MyName} </row> <!-- The following row shows how print the array contents--> <row id='second'> I'm the index 'bar' of foo {$bar['foo']} </row> <!-- Now we get the text to print from the custom function foo or foop--> <row> Output from the function foo: {foo()} </row> <row> Function with one parameter: {foop('hello world')} </row> <!-- Row position. We print the following row two row after the last printed one --> <row VPos='Relative' RowPos='+2'> 2 row after 'Function with one parameter' </row> <!-- We are able to move back. We print the following row two row before the last printed one --> <row VPos='Relative' RowPos='-2'> Before the last one </row> <!-- The following text will be printed at row 20 --> <row VPos='absolute' RowPos='20'> At line 20 </row> <!-- Change page, the text will be the first on the new page --> <row VPos='NewPage'> New page, First Line!!! </row> <!-- Another method to change page. Note, the module changes the page automatically when it reach the page end. This tag allow you to force the new page --> <newpage/> <row>Another page</row> <row vpos='absolute' rowpos='5'/> <closepage> Page end </closepage> <closereport> End!That's all folk! </closereport> </report> </template> |