User:X!/PHPtemp

Documentation for the PHPtemp template.

Syntax
At the moment, PHPtemp can do 5 simple tasks.


 * is replaced with the  line from a PHP configuration file. (see sample .conf file)
 * is replaced with  when this code is called:
 * will render as  if foo is set with the   function.
 * returns 2.

The last function is hard to describe, so I'll do the best that I can. It is designed to replicate the PHP built in foreach function.

{&foreach: arr= key={^k^} var={^v^}&} With the key {^k^}, the value is {^v^}. {&endforeach&}

When called with, here's what the output would be:

With the key foo, the value is bar. With the key fu, the value is baz.

Single-instance method
[main] title = "Test PHPtemp page" {#title#}
 * 1) Create a file called "en.conf", with the following contents:
 * 1) Create a file called main.tpl with the following contents:

{$content$}  {&foreach arr= key={^number^} val={^v^}&} Line #{^number^}: {^v^} {&endforeach&}  getLang;

$phptemp->load_config( '/absolute/path/to/conf/file/'.$lang.'.conf', 'main' );

$phptemp->assign( "header", "Testing PHPtemp" ); $phptemp->assign( "content", "Here's an unordered list of a certain array:" ); $phptemp->assign( "listarr", serialize( array( 'foo', 'bar' ) ) );

$phptemp->display;

?>

Result
Test PHPtemp page Testing PHPtemp Here's an unordered list of a certain array:  Line #0: foo Line #1: bar 

Multi-instance method
This method is useful for a web site that has multiple pages. What's better about this method is that if you make a change to the tag, or another section of the common template, you don't have to update every single page.

Hierarchy: >dir >>configs >>templates >>app >>>configs >>>templates

[main] title = "Test PHPtemp page" {#title#} {$content$} [app] header = "Testing PHPtemp" {#header#} {$content$}  {&foreach arr= key={^number^} val={^v^}&} Line #{^number^}: {^v^} {&endforeach&}  <?php
 * 1) Create a file called "en.conf" in the dir/configs directory, with the following contents:
 * 1) Create a file called "main.tpl" in the dir/templates directory, with the following contents:
 * 1) Create a file called "en.conf" in the dir/app/configs directory, with the following contents:
 * 1) Create a file called "app.tpl" in the dir/app/templates directory, with the following contents:
 * 1) Create your dir/app/app.php file with the following contents:

require_once( '/absolute/path/to/phptemp/class/phptemp.class.php' ); require_once( '/absolute/path/to/lang/class/language.class.php' );

$phptemp = new PHPtemp( '/absolute/path/to/dir/templates/main.tpl' ); $content = new PHPtemp( '/absolute/path/to/dir/app/templates/app.tpl' );

$language = new Language( array( 'en' ) ); $lang = $language->getLang;

$phptemp->load_config( '/absolute/path/to/dir/configs/'.$lang.'.conf', 'main' ); $content->load_config( '/absolute/path/to/dir/app/configs/'.$lang.'.conf', 'app' );

$content->assign( "content", "Here's an unordered list of a certain array:" ); $content->assign( "listarr", serialize( array( 'foo', 'bar' ) ) );

$phptemp->assign( "content", $content->display( true ) ); $phptemp->display;

?>

Result
Test PHPtemp page Testing PHPtemp Here's an unordered list of a certain array:  <li>Line #0: foo</li> <li>Line #1: bar</li> </ul>