Documentation::Template Syntax - AvantTemplate: Template Class for PHP

DOWNLOAD
Documentation
+Prerequisite
+Step by step
+Template Syntax
Home

AvanTemplate Logo SourceForge Logo
Template syntax

  1. Variable replacement
    variable to be replace is written like this. "[%name%]". "[%" is called "prepend" and "%]" is called "append".
    Template:
    <HTML><BODY>[%name%]</BODY></HTML>
    Method:
    $t->setValue('name', 'Joe the programmer');
    Result:
    <HTML><BODY>Joe the programmer</BODY></HTML>
  2. BLOCK
    BLCOK allows you to set block of text to be shown or hidden. Starting tag: "[%BLOCK" followed by underscore "_", then name of the block(this time "isblack", and end with underscore "_" followed by "START%]". Ending tag: "[%BLOCK" followed by underscore "_", then name of the block(this time "isblack", and end with underscore "_" followed by "END%]". hideBlock() suppresses the output inside the BLOCK and showBlock() does not suppress the inside of the BLOCK. When neither of them are called, inside of the BLOCK will be suppressed.
    Template:
    <HTML><BODY>[%BLOCK_isblack_START%]It's BLACK![%BLOCK_isblack_END%]</BODY></HTML>
    Method:
    $t->hideBlock('isblack');
    Or
    $t->showBlock('isblack');
    Result:
    When hideBlock() is called: <HTML><BODY></BODY></HTML>
    When showBlock() is called: <HTML><BODY>It's BLACK!</BODY></HTML>
  3. File inclusion. File name specified in template file.
    You can specify which file to include in template file. This allows web designer to work more independently that she/he can specify external template file her/himself(Like header.html and footer.html). "[%INCLUDE" followed by underscore "_", then name of the file(this time "footer.html"), end with "%]".
    Template:
    <HTML><BODY>[%INCLUDE_footer.html%]</BODY></HTML>
    Method:
    Not needed.
    Result:
    <HTML><BODY>contents of the footer here!</BODY></HTML>
  4. File inclusion. File name specified by method.
    You can specify which file to include by its command. This allows you to specify filename conditionally. Place this in global design template, always load this file as your template file in format(), and specify which template file in script to differentiate template which is script dependent. This way you can specify site wide design and layout in one file. "[%INCLUDE" followed by colon ":", then name of the file handle(this time "content"), end with "%]".
    Template:
    <HTML><BODY>[%INCLUDE:content%]</BODY></HTML>
    Method:
    $t->includeFile('content','example.html');
    Result:
    <HTML><BODY>contents of example.html here!</BODY></HTML>
  5. Multi-depth LOOP
    Staring tag: "[%LOOP" followed by underscore "_" and name of the LOOP(this time, they are "menu" and "submenu") end with undersocre "_" and "START%]. End tag: "[%LOOP" followed by underscore "_" and name of the LOOP(this time, they are "menu" and "submenu") end with undersocre "_" and "END%]". To set variable inside the loop, you must make array or object with its key being name of the variable, and its value being value to replace the variable. Name of the variable inside LOOP preceded by name of the LOOP the variable resides delimitied by period ".". If LOOP is to be a child of another loop, then its name must be preceded by name of the parent LOOP, again, delimited by period "." as shown in this example.
    Template:
    [%LOOP_menu_START%] <A [%menu.attr%]>[%menu.str%]</A><BR/> [%LOOP_menu.submenu_START%] +<A [%menu.submenu.attr%]>[%menu.submenu.str%]</A><BR/> [%LOOP_menu.submenu_END%] [%LOOP_menu_END%]
    Method:
    $doc = array('attr' => 'href="/docs/"','str'=>'DOCUMENTATION');
    $doc_id = $t->setValue('menu',$doc,1);
    $submenu->str = 'Prerequisite';
    $submenu->attr = 'href="/docs/prerequisite.html"';
    $t->setChildValue($doc_id,'submenu',$submenu, 1);
    $home = array('attr' => 'href="/"','str'=>'HOME');
    $t->setValue('menu',$home,1);
    Result:
    <A href="/docs"/>DOCUMENTATION</A><BR/> +<A href="/docs/prerequisite.html">Prerequisite</A><BR/> <A href="/">HOME</A><BR/>

Author: Naoki Shima; E-mail: naoki at avantexchange dot com; All Copyrights Reserved. ©