[ Index ]
 

Code source de PHP PEAR 1.4.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/HTML/Template/ -> IT.php (sommaire)

(pas de description)

Poids: 1001 lignes (32 kb)
Inclus ou requis: 2 fois
Référencé: 0 fois
Nécessite: 1 fichier
 PEAR.php

Définit 1 class

HTML_Template_IT:: (22 méthodes):
  HTML_Template_IT()
  setOption()
  setOptions()
  show()
  get()
  parse()
  parseCurrentBlock()
  setVariable()
  setCurrentBlock()
  touchBlock()
  init()
  free()
  setTemplate()
  loadTemplatefile()
  setRoot()
  buildBlockvariablelist()
  getGlobalvariables()
  findBlocks()
  getFile()
  _addPregDelimiters()
  _preserveOpeningDelimiter()
  errorMessage()


Classe: HTML_Template_IT  - X-Ref

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:
<code>$tpl->setCurrentBlock("block1");</code>
and repeat this as often as needed:
<code>
$tpl->setVariable(...);
$tpl->parseCurrentBlock();
</code>

To add content to block2 you would type something like:
<code>
$tpl->setCurrentBlock("inner1");
$tpl->setVariable(...);
$tpl->parseCurrentBlock();

$tpl->setVariable(...);
$tpl->parseCurrentBlock();

$tpl->parse("block1");
</code>

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:
<code>
$tpl = new HTML_Template_IT( [string filerootdir] );

// load a template or set it with setTemplate()
$tpl->loadTemplatefile( string filename [, boolean removeUnknownVariables, boolean removeEmptyBlocks] )

// set "global" Variables meaning variables not beeing within a (inner) block
$tpl->setVariable( string variablename, mixed value );

// like with the Isotemplates there's a second way to use setVariable()
$tpl->setVariable( array ( string varname => mixed value ) );

// Let's use any block, even a deeply nested one
$tpl->setCurrentBlock( string blockname );

// repeat this as often as you need it.
$tpl->setVariable( array ( string varname => mixed value ) );
$tpl->parseCurrentBlock();

// get the parsed template or print it: $tpl->show()
$tpl->get();
</code>

HTML_Template_IT($root = '', $options = null)   X-Ref
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.

param: string    File root directory, prefix for all filenames

setOption($option, $value)   X-Ref
Sets the option for the template class

param: string  option name
param: mixed   option value
return: mixed   IT_OK on success, error object on failure

setOptions($options)   X-Ref
Sets the options for the template class

param: string  options array of options
param: mixed   option value
return: mixed   IT_OK on success, error object on failure

show($block = '__global__')   X-Ref
Print a certain block with all replacements done.


get($block = '__global__')   X-Ref
Returns a block with all replacements done.

param: string     name of the block
return: string

parse($block = '__global__', $flag_recursion = false)   X-Ref
Parses the given block.

param: string    name of the block to be parsed

parseCurrentBlock()   X-Ref
Parses the current block


setVariable($variable, $value = '')   X-Ref
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().

param: mixed     string with the variable name or an array
param: string    value of the variable or empty if $variable
param: string    prefix for variable names

setCurrentBlock($block = '__global__')   X-Ref
Sets the name of the current block that is the block where variables
are added.

param: string      name of the block
return: boolean     false on failure, otherwise true

touchBlock($block)   X-Ref
Preserves an empty block even if removeEmptyBlocks is true.

param: string      name of the block
return: boolean     false on false, otherwise true

init()   X-Ref
Clears all datafields of the object and rebuild the internal blocklist

LoadTemplatefile() and setTemplate() automatically call this function
when a new template is given. Don't use this function
unless you know what you're doing.


free()   X-Ref
Clears all datafields of the object.

Don't use this function unless you know what you're doing.


setTemplate( $template, $removeUnknownVariables = true,$removeEmptyBlocks = true)   X-Ref
Sets the template.

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

param: string      template content
param: boolean     remove unknown/unused variables?
param: boolean     remove empty blocks?
return: boolean

loadTemplatefile( $filename,$removeUnknownVariables = true,$removeEmptyBlocks = true )   X-Ref
Reads a template file from the disk.

param: string      name of the template file
param: bool        how to handle unknown variables.
param: bool        how to handle empty blocks.
return: boolean    false on failure, otherwise true

setRoot($root)   X-Ref
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.

param: string

buildBlockvariablelist()   X-Ref
Build a list of all variables within of a block


getGlobalvariables()   X-Ref
Returns a list of all global variables


findBlocks($string)   X-Ref
Recusively builds a list of all blocks within the template.

param: string    string that gets scanned

getFile($filename)   X-Ref
Reads a file from disk and returns its content.

param: string    Filename
return: string    Filecontent

_addPregDelimiters($str)   X-Ref
Adds delimiters to a string, so it can be used as a pattern
in preg_* functions

param: string
return: string

_preserveOpeningDelimiter($str)   X-Ref
Replaces an opening delimiter by a special string

param: string
return: string

errorMessage($value, $blockname = '')   X-Ref
Return a textual error message for a IT error code

param: integer $value error code
return: string error message, or false if the error code was



Généré le : Sun Feb 25 14:08:00 2007 par Balluche grâce à PHPXref 0.7