HTML_Template_IT
[ class tree: HTML_Template_IT ] [ index: HTML_Template_IT ] [ all elements ]

Class: HTML_Template_IT

Source Location: /HTML_Template_IT-1.3.0/HTML/Template/IT.php

Class Overview


Integrated Template - IT


Author(s):

Variables

Methods


Child classes:

HTML_Template_ITX
Integrated Template Extension - ITX

Inherited Variables

Inherited Methods


Class Details

[line 138]
Integrated Template - IT

Well there's not much to say about it. I needed a template class that supports a single template file with multiple (nested) blocks inside and a simple block API.

The Isotemplate API is somewhat tricky for a beginner although it is the best one you can build. template::parse() [phplib template = Isotemplate] requests you to name a source and a target where the current block gets parsed into. Source and target can be block names or even handler names. This API gives you a maximum of fexibility but you always have to know what you do which is quite unusual for php skripter like me.

I noticed that I do not any control on which block gets parsed into which one. If all blocks are within one file, the script knows how they are nested and in which way you have to parse them. IT knows that inner1 is a child of block2, there's no need to tell him about this.

<table border> <tr> <td colspan=2> __global__ <p> (hidden and automatically added) </td> </tr> <tr> <td>block1</td> <td> <table border> <tr> <td colspan=2>block2</td> </tr> <tr> <td>inner1</td> <td>inner2</td> </tr> </table> </td> </tr> </table>

To add content to block1 you simply type:

  1. $tpl->setCurrentBlock("block1");
and repeat this as often as needed:
  1.    $tpl->setVariable(...);
  2.    $tpl->parseCurrentBlock();

To add content to block2 you would type something like:

  1.  $tpl->setCurrentBlock("inner1");
  2.  $tpl->setVariable(...);
  3.  
  4.  $tpl->setVariable(...);
  5.  
  6.  $tpl->parse("block1");

This will result in one repition of block1 which contains two repitions of inner1. inner2 will be removed if $removeEmptyBlock is set to true which is the default.

Usage:

  1.  $tpl = new HTML_Template_IT[string filerootdir);
  2.  
  3.  // load a template or set it with setTemplate()
  4.  $tpl->loadTemplatefilestring filename [boolean removeUnknownVariablesboolean removeEmptyBlocks)
  5.  
  6.  // set "global" Variables meaning variables not beeing within a (inner) block
  7.  $tpl->setVariablestring variablenamemixed value );
  8.  
  9.  // like with the Isotemplates there's a second way to use setVariable()
  10.  $tpl->setVariablearray string varname => mixed value ) );
  11.  
  12.  // Let's use any block, even a deeply nested one
  13.  $tpl->setCurrentBlockstring blockname );
  14.  
  15.  // repeat this as often as you need it.
  16.  $tpl->setVariablearray string varname => mixed value ) );
  17.  
  18.  // get the parsed template or print it: $tpl->show()
  19.  $tpl->get();



[ Top ]


Class Variables

$blocknameRegExp =  '[\.0-9A-Za-z_-]+'

[line 180]

RegExp matching a block in the template.

Per default "sm" is used as the regexp modifier, "i" is missing. That means a case sensitive search is done.


Type:   string


[ Top ]

$clearCache =  false

[line 154]

Clear cache on get()?

Type:   boolean


[ Top ]

$clearCacheOnParse =  false

[line 333]

Clear the variable cache on parse?

If you're not an expert just leave the default false. True reduces memory consumption somewhat if you tend to add lots of values for unknown placeholder.

  • Access: public

Type:   boolean


[ Top ]

$closingDelimiter =  '}'

[line 170]

Last character of a variable placeholder ( {VARIABLE_}_ ).

Type:   string


[ Top ]

$err = array()

[line 146]

Contains the error objects
  • See: halt(), $printError, $haltOnError
  • Access: public

Type:   array


[ Top ]

$openingDelimiter =  '{'

[line 162]

First character of a variable placeholder ( _{_VARIABLE} ).

Type:   string


[ Top ]

$removeEmptyBlocks =  true

[line 219]

Controls the handling of empty blocks, default is remove.
  • Access: public

Type:   boolean


[ Top ]

$removeUnknownVariables =  true

[line 212]

Controls the handling of unknown variables, default is remove.
  • Access: public

Type:   boolean


[ Top ]

$variablenameRegExp =  '[\.0-9A-Za-z_-]+'

[line 190]

RegExp matching a variable placeholder in the template.

Per default "sm" is used as the regexp modifier, "i" is missing. That means a case sensitive search is done.


Type:   string


[ Top ]



Method Detail

HTML_Template_IT (Constructor)   [line 410]

HTML_Template_IT HTML_Template_IT( [string $root = ''], [mixed $options = null])

Builds some complex regular expressions and optinally sets the file root directory.

Make sure that you call this constructor if you derive your template class from this one.


Parameters:

string   $root   —  File root directory, prefix for all filenames given to the object.
mixed   $options   —  Unknown

[ Top ]

checkPlaceholderExists   [line 734]

bool checkPlaceholderExists( $blockname, $placeholder)

Checks to see if a placeholder exists within a block (and its children)
  • Access: public

Parameters:

   $blockname   — 
   $placeholder   — 

[ Top ]

get   [line 509]

string get( [string $block = '__global__'])

Returns a block with all replacements done.

Parameters:

string   $block   —  name of the block

[ Top ]

getGlobalvariables   [line 987]

array getGlobalvariables( )

Returns a list of all global variables
  • Access: public

[ Top ]

loadTemplatefile   [line 920]

boolean loadTemplatefile( string $filename, [bool $removeUnknownVariables = true], [bool $removeEmptyBlocks = true])

Reads a template file from the disk.

Parameters:

string   $filename   —  name of the template file
bool   $removeUnknownVariables   —  how to handle unknown variables.
bool   $removeEmptyBlocks   —  how to handle empty blocks.

[ Top ]

parse   [line 558]

null parse( [string $block = '__global__'], [bool $flag_recursion = false])

Parses the given block.

Parameters:

string   $block   —  name of the block to be parsed
bool   $flag_recursion   —  unknown

[ Top ]

parseCurrentBlock   [line 723]

null parseCurrentBlock( )

Parses the current block

[ Top ]

setCurrentBlock   [line 786]

boolean setCurrentBlock( [string $block = '__global__'])

Sets the name of the current block that is the block where variables are added.
  • Return: false on failure, otherwise true
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $block   —  name of the block

[ Top ]

setOption   [line 440]

mixed setOption( string $option, mixed $value)

Sets the option for the template class
  • Return: IT_OK on success, error object on failure
  • Access: public

Parameters:

string   $option   —  option name
mixed   $value   —  option value

[ Top ]

setOptions   [line 471]

mixed setOptions( string[] $options)

Sets the options for the template class
  • Return: IT_OK on success, error object on failure
  • See: $options
  • Access: public

Parameters:

string[]   $options   —  options array of options default value: 'preserve_data' => false, 'use_preg' => true

[ Top ]

setRoot   [line 951]

null setRoot( string $root)

Sets the file root. The file root gets prefixed to all filenames passed to the object.

Make sure that you override this function when using the class on windows.


Parameters:

string   $root   —  File root

[ Top ]

setTemplate   [line 883]

boolean setTemplate( string $template, [bool $removeUnknownVariables = true], [bool $removeEmptyBlocks = true])

Sets the template.

You can eighter load a template file from disk with LoadTemplatefile() or set the template manually using this function.

  • See: LoadTemplatefile(), $template
  • Access: public

Parameters:

string   $template   —  template content
bool   $removeUnknownVariables   —  how to handle unknown variables.
bool   $removeEmptyBlocks   —  how to handle empty blocks.

[ Top ]

setVariable   [line 763]

null setVariable( mixed $variable, [string $value = ''])

Sets a variable value.

The function can be used eighter like setVariable( "varname", "value") or with one array $variables["varname"] = "value" given setVariable($variables) quite like phplib templates set_var().

  • Access: public

Parameters:

mixed   $variable   —  string with the variable name or an array %variables["varname"] = "value"
string   $value   —  value of the variable or empty if $variable is an array.

[ Top ]

show   [line 494]

null show( [string $block = '__global__'])

Print a certain block with all replacements done.
  • Access: public

Parameters:

string   $block   —  block

[ Top ]

touchBlock   [line 812]

boolean touchBlock( string $block)

Preserves an empty block even if removeEmptyBlocks is true.

Parameters:

string   $block   —  name of the block

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:36:53 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.