{variablename}
|
<!-- START BLOCK : blockname --> <!-- END BLOCK : blockname --> |
<!-- INCLUDE BLOCK : iblockname --> |
<!-- INCLUDE BLOCK : ./header.tpl --> |
<!-- INCLUDESCRIPT BLOCK : iblockname --> |
<!-- INCLUDESCRIPT BLOCK : ./header.php --> |
<!-- START IGNORE --> <!-- END IGNORE --> |
<!-- REUSE BLOCK : orig_bname AS copy_bname --> |
//create a new TemplatePower object using a file |
//create a new TemplatePower object using a file |
| simple.tpl
<html> <head> <title>Simple Template Example</title> </head> <body> <H2>Welcome {name}!</H2> </body> </html> |
myscript.php
<?php include_once( "./class.TemplatePower.inc.php" ); $tpl = new TemplatePower( "./simple.tpl" ); $tpl->prepare(); $tpl->assign( "name", "Ron" ); $tpl->printToScreen(); ?> |
$tpl->assign( "name", "Ron" );
$tpl->assign( Array( product_id => $pid,
productname => $pname ));
|
$tpl->assign( "_ROOT.name", "Ron" ); $tpl->assign( "book.title", "Core PHP Programming" ); |
| img.tpl
<html> <head> <title>AssignGlobal Example</title> </head> <body> <img src="{imagedir}/logo.gif"> <!-- START BLOCK : image --> <img src="{imagedir}/img_{id}.gif"> <!-- END BLOCK : image --> </body> </html> |
myscript.php
<?php
include_once( "./class.TemplatePower.inc.php" );
$tpl = new TemplatePower( "./img.tpl" );
$tpl->prepare();
$tpl->assignGlobal( "imagedir", "images");
for ( $i=1; $i<=10; $i++ )
{
$tpl->newBlock( "image" );
$tpl->assign( "id", $i );
}
$tpl->printToScreen();
?>
|
$tpl->assignGlobal( "basedir", "/usr/local/apache/www/");
$tpl->assignGlobal( Array( basedir => "/usr/local/apache/www/",
imagedir => "images/" ));
|
| include.tpl
<html> <head> <title>AssignInclude Exemplo</title> </head> <body> <!-- INCLUDE BLOCK : header --> <!-- INCLUDESCRIPT BLOCK : content --> </body> </html> |
myscript.php
<?php include_once( "./class.TemplatePower.inc.php" ); $tpl = new TemplatePower( "./include.tpl" ); $tpl->assignInclude( "header", "./header.tpl" ); $tpl->assignInclude( "content", "./about.php" ); $tpl->prepare(); $tpl->printToScreen(); ?> |
$tpl->assignInclude( "header", "./header.tpl" ); $tpl->assignInclude( "content", $content, T_BYVAR ); |
<?php
include( "./class.TemplatePower.inc.php");
//connect to database
$link = mysql_connect("host", "user", "passwd")
or die("Could not connect");
mysql_select_db("my_database")
or die("Could not select database");
//get database templates
$qry = "SELECT base, header FROM templates";
$result = mysql_query($qry);
if( mysql_num_rows($result) > 0)
{
list($base, $header) = mysql_fetch_row($result);
}
//make a new TemplatePower object
$tpl = new TemplatePower( $base, T_BYVAR );
//assign include template by variable
$tpl->assignInclude( "header", $header, T_BYVAR );
$tpl->prepare();
//print the result
$tpl->printToScreen();
?>
|
| number.tpl
<html> <head> <title>AssignInclude Exemplo</title> </head> <body> <!-- START BLOCK : number --> {number} <!-- END BLOCK : number --> {total} </body> </html> |
myscript.php
<?php
include_once( "./class.TemplatePower.inc.php" );
$tpl = new TemplatePower( "./number.tpl" );
$tpl->prepare();
for( $i=1; $i <= 10; $i++ )
{
$tpl->newBlock( "number" );
$tpl->assign( "number" , $i );
$tpl->assign( "_ROOT.total", ($tpl->getVarValue( "_ROOT.total" ) + $i) );
}
$tpl->printToScreen();
?>
|
newBlock.tpl
<html>
<head>
<title>NewBlock</title>
</head>
<body>
<table>
<tr><td>Names</td></tr>
<!-- START BLOCK : name_row -->
<tr>
<td>{name}</td>
</tr>
<!-- END BLOCK : name_row -->
</table>
<br>
{total_names}
</body>
</html>
|
myscript.php
<?php
include_once( "./class.TemplatePower.inc.php" );
$tpl = new TemplatePower( "./newBlock.tpl" );
$tpl->prepare();
$count = 0;
while( $count < 10 )
{
$tpl->newBlock( "name_row" );
$tpl->assign( "name", "Ron" );
$count++;
}
$tpl->gotoBlock( "_ROOT" );
$tpl->assign( "total_names", $count );
$tpl->printToScreen();
?>
|
newBlock.tpl
<html>
<head>
<title>NewBlock</title>
</head>
<body>
<table>
<tr><td>Names</td></tr>
<!-- START BLOCK : name_row -->
<tr>
<td>{name}</td>
</tr>
<!-- END BLOCK : name_row -->
</table>
<br>
{total_names}
</body>
</html>
|
myscript.php
<?php
include_once( "./class.TemplatePower.inc.php" );
$tpl = new TemplatePower( "./newBlock.tpl" );
$tpl->prepare();
$count = 0;
while( $count < 10 )
{
$tpl->newBlock( "name_row" );
$tpl->assign( "name", "Ron" );
$count++;
}
$tpl->gotoBlock( "_ROOT" );
$tpl->assign( "total_names", $count );
$tpl->printToScreen();
?>
|
form.tpl
<html>
<head>
<title></title>
</head>
<body>
<!-- START BLOCK : error -->
The following errors occurred.<br>
<!-- START BLOCK : message -->
- {message}<br>
<!-- END BLOCK : message -->
<!-- END BLOCK : error -->
<form method="post" action="myscript.php">
Email:
<input type="text" name="email">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
|
myscript.php
<?php
include_once('./class.TemplatePower.inc.php');
$tpl = new TemplatePower('form.tpl');
$tpl->prepare();
$errorMessage = Array();
$errorFound = false;
if( isset( $submit ) )
{
if($email == '')
{
$errorMessage[] = 'No emailadress entered';
$errorFound = true;
}
if( $errorFound )
{
$tpl->newBlock('error');
$size = sizeof($errorMessage);
for( $i=0; $i < $size; $i++ )
{
$tpl->newBlock('message');
$tpl->assign('message', $errorMessage[$i]);
}
}
else
{
Header('Location: member.php');
}
}
$tpl->printToScreen();
?>
|