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.

newBlock

(unknown)

Create a new block.

Description

newBlock ( string blockname )

After using the function newBlock() TemplatePower will set the 'blockpointer' to the block blockname. So, if you want to assign a variable of an other block, you have to move the 'blockpointer' to that block (see gotoBlock() ) or use the variablename in combination with its blockname (see Variables and Blocks). If you don't TemplatePower will assume that the variable is part of the currentblock.

Example 1.
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();
?>


If you don't use the function newBlock() to create a block, the code inside the block will be hidden. In 'Example 2' you see an example of this where an emailaddress can be submitted by a form. If no emailadress is enterred an errormessage will be printed.
Example 2.
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();
?>

 

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