home    download    forum    manual    awards    faq    bugs    links

TemplatePower manual




Arabic
Deutsch
Dutch
English
Italian
Portuguese (Brazilian)
Russian
Spanish


* Not fully translated yet.




Looking for the manual in your language? Well, I need translators to translate the manual to any language. So, if you have some sparetime please sign up!

Just email to sign up:
rovel999_AT_codocad_DOT_com

If you have signed up you will receive more information about the translation.

TemplatePower Basics!

Creating a template

At first you design a page, this is the point we start from. On the page there are probably places where you want to put variable information. Just type on that place {a_unique_varname}, for example: {name}. By doing this TemplatePower will recognize it as a variable, which can be accessed by your template controllscript like this:


 
$tpl->assign( "name", "RoVeL" );

On all places in the template where you write {name}in the block where the variable is a child from, "RoVeL" will be written.

Note: look here for details about the format of template variables.

Here's a very simple example download all example's):

simple.tpl

<html>
<head>
  <title>Simple Template Example</title>
</head>

<body>

  <H2>Welcome {name}!</H2>

</body>
</html>


simple_example.php

<?php
 include( "./class.TemplatePower.inc.php" );

 //make a new TemplatePower object
  $tpl = new 
TemplatePower( "./simple.tpl" );

 //let TemplatePower do its thing, parsing etc.
  $tpl->prepare();

 //assign a value to {name}
  $tpl->assign( "name", "RoVeL" );

 //print the result
  $tpl->printToScreen();
?>
 

click here to see the result


Note: if you create a new TemplatePower object the filename you passtrough is the base template file. In this base template file you can define include blocks. These blocks can be assigned by the assignInclude function, click here to read more about this.


Its very likely that you want parts of the template to be repeated. For example a table with products, with on each tablerow a different productnumber, productname and price. This is possible by putting the following line before it (on an empty private line):


<!-- START BLOCK : a_block_name -->

and after it (on an empty private line too):


<!-- END BLOCK : a_block_name -->

Note: look here for details about the format of template blocks.


Here's a more advanced template with repeating blocks (download all example's):

adv_example1.tpl


<html>
<head>
  <title>Advanced Template Example</title>
</head>

<body>
<table>
  <tr>
    <td>n</td>
    <td>n*10</td>
  </tr>
 <!-- START BLOCK : number_row -->
  <tr>
    <td>{number}</td>
    <td>{bignumber}</td>
  </tr>
 <!-- END BLOCK : number_row -->
</table>
</body>
</html>

adv_example1.php


<?php

 include( "./class.TemplatePower.inc.php");

 //make a new TemplatePower object
  $tpl = new 
TemplatePower( "./adv_example1.tpl" );

 //let TemplatePower do its thing, parsing etc.
  $tpl->prepare();

  for( $i=1; $i <= 10; $i++ )
  {
     //create a new number_row block
      $tpl->newBlock("number_row");

     //assign values
      $tpl->assign("number"   , $i );
      $tpl->assign("bignumber", $i * 10 );
  }

 //print the result
  $tpl->printToScreen();
?>

click here to see the result

You also might want to include a template or just plain html, for example a header which you use on every page. Just add the following line to your code:


<!-- INCLUDE BLOCK : include_block_name -->

In you template controllscript you can tell TemplatePower which file include_block_name represents by doing:

  
$tpl->assignInclude( "include_block_name", "./a_file.tpl" );


Here's a template with an include block (download all example's):

Adv_example2.tpl


<html>
<head>
  <title>Include Block Example</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<!-- INCLUDE BLOCK : header -->

 <p>
  <!-- START BLOCK : text_row -->
    Chapter Text {number}.<br>
  <!-- END BLOCK : text_row -->
 </p>
</body>
</html>

adv2_header.tpl:


<table width="550" border="0">
  <tr>
    <td height="58" bgcolor="#CCCCCC">
      <h2>Chapter {chapter_num} {chapter_name}</h2>
    </td>
  </tr>
  <tr>
    <td height="29">
      <h3>{subject}</h3>
    </td>
  </tr>
</table>


adv_example2.php:


<?php

 include( "./class.TemplatePower.inc.php");

 //make a new TemplatePower object
  $tpl = new 
TemplatePower( "./adv_example2.tpl" );

 //tell TemplatePower which tplfile to use
  $tpl->assignInclude( "header", "./adv2_header.tpl" );

 //let TemplatePower do its thing, parsing etc.
  $tpl->prepare();

 //assign values for header
  $tpl->assign( "chapter_num" , "7." );
  $tpl->assign( "chapter_name", "Variables" );
  $tpl->assign( "subject"     , "Basics" );

  for( $i=1; $i <= 10; $i++ )
  {
     //create a new text_row block
      $tpl->newBlock("text_row");

     //assign value
      $tpl->assign("number", $i );
  }

 //print the result
  $tpl->printToScreen();
?>


click here to see the result
 

 
CopyRights © 2001-2009 Ron. P.J. Velzeboer.