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

Class: HTML_Template_ITX

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

Class Overview

HTML_Template_IT
   |
   --HTML_Template_ITX

Integrated Template Extension - ITX


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods

Class: HTML_Template_IT

HTML_Template_IT::HTML_Template_IT()
Builds some complex regular expressions and optinally sets the file root directory.
HTML_Template_IT::checkPlaceholderExists()
Checks to see if a placeholder exists within a block (and its children)
HTML_Template_IT::get()
Returns a block with all replacements done.
HTML_Template_IT::getGlobalvariables()
Returns a list of all global variables
HTML_Template_IT::loadTemplatefile()
Reads a template file from the disk.
HTML_Template_IT::parse()
Parses the given block.
HTML_Template_IT::parseCurrentBlock()
Parses the current block
HTML_Template_IT::setCurrentBlock()
Sets the name of the current block that is the block where variables are added.
HTML_Template_IT::setOption()
Sets the option for the template class
HTML_Template_IT::setOptions()
Sets the options for the template class
HTML_Template_IT::setRoot()
Sets the file root. The file root gets prefixed to all filenames passed to the object.
HTML_Template_IT::setTemplate()
Sets the template.
HTML_Template_IT::setVariable()
Sets a variable value.
HTML_Template_IT::show()
Print a certain block with all replacements done.
HTML_Template_IT::touchBlock()
Preserves an empty block even if removeEmptyBlocks is true.

Class Details

[line 53]
Integrated Template Extension - ITX

With this class you get the full power of the phplib template class. You may have one file with blocks in it but you have as well one main file and multiple files one for each block. This is quite usefull when you have user configurable websites. Using blocks not in the main template allows you to modify some parts of your layout easily.

Note that you can replace an existing block and add new blocks at runtime. Adding new blocks means changing a variable placeholder to a block.



[ Top ]


Class Variables

$functionnameRegExp =  '[_a-zA-Z]+[A-Za-z_0-9]*'

[line 98]

Functionname RegExp.
  • Access: public

Type:   string


[ Top ]

$functionPrefix =  'func_'

[line 91]

Functionnameprefix used when searching function calls in the template.
  • Access: public

Type:   string


[ Top ]

$haltOnWarning =  false

[line 77]

Call die() on warning?

Type:   boolean


[ Top ]

$printWarning =  false

[line 69]

Print warnings?

Type:   array


[ Top ]

$warn = array()

[line 61]

Array with all warnings.

Type:   array


[ Top ]



Method Detail

HTML_Template_ITX (Constructor)   [line 139]

HTML_Template_ITX HTML_Template_ITX( [string $root = ''])

Builds some complex regexps and calls the constructor of the parent class.

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


Parameters:

string   $root   —  Root node?

[ Top ]

addBlock   [line 285]

boolean addBlock( string $placeholder, string $blockname, string $template)

Adds a block to the template changing a variable placeholder to a block placeholder.

Add means "replace a variable placeholder by a new block". This is different to PHPLibs templates. The function loads a block, creates a handle for it and assigns it to a certain variable placeholder. To to the same with PHPLibs templates you would call set_file() to create the handle and parse() to assign the parsed block to a variable. By this PHPLibs templates assume that you tend to assign a block to more than one one placeholder. To assign a parsed block to more than only the placeholder you specify in this function you have to use a combination of getBlock() and setVariable().

As no updates to cached data is necessary addBlock() and addBlockfile() are rather "cheap" meaning quick operations.

The block content must not start with <!-- BEGIN blockname --> and end with <!-- END blockname --> this would cause overhead and produce an error.


Parameters:

string   $placeholder   —  Name of the variable placeholder, the name must be unique within the template.
string   $blockname   —  Name of the block to be added
string   $template   —  Content of the block

[ Top ]

addBlockfile   [line 361]

null addBlockfile( string $placeholder, string $blockname, string $filename)

Adds a block taken from a file to the template changing a variable placeholder to a block placeholder.
  • Access: public

Parameters:

string   $placeholder   —  Name of the variable placeholder to be converted
string   $blockname   —  Name of the block to be added
string   $filename   —  File that contains the block

[ Top ]

blockExists   [line 621]

boolean blockExists( string $blockname)

Checks wheter a block exists.

Parameters:

string   $blockname   —  Blockname

[ Top ]

BlockvariableExists   [line 659]

boolean BlockvariableExists( string $block, string $variable)

Checks wheter a block variable exists.

Parameters:

string   $block   —  Blockname
string   $variable   —  Variablename

[ Top ]

findPlaceholderBlocks   [line 839]

array findPlaceholderBlocks( string $variable)

Returns an array of blocknames where the given variable placeholder is used.
  • Return: parents[0..n] = blockname
  • Access: public

Parameters:

string   $variable   —  Variable placeholder

[ Top ]

getBlocklist   [line 602]

array getBlocklist( )

Returns a list of blocknames in the template.

[ Top ]

getBlockvariables   [line 635]

array getBlockvariables( string $block)

Returns a list of variables of a block.

Parameters:

string   $block   —  Blockname

[ Top ]

getFunctioncalls   [line 465]

array getFunctioncalls( )

Returns a list of all function calls in the current template.
  • Access: public

[ Top ]

performCallback   [line 430]

null performCallback( )

Checks the list of function calls in the template and calls their callback function.
  • Access: public

[ Top ]

placeholderExists   [line 381]

string placeholderExists( string $placeholder, [string $block = ''])

Returns the name of the (first) block that contains the specified placeholder.
  • Return: Name of the (first) block that contains the specified placeholder. If the placeholder was not found or an error occured an empty string is returned.
  • Throws: IT_Error
  • Access: public

Parameters:

string   $placeholder   —  Name of the placeholder you're searching
string   $block   —  Name of the block to scan. If left out (default) all blocks are scanned.

[ Top ]

replaceBlock   [line 198]

boolean replaceBlock( string $block, string $template, [boolean $keep_content = false])

Replaces an existing block with new content.

This function will replace a block of the template and all blocks contained in the replaced block and add a new block insted, means you can dynamically change your template.

Note that changing the template structure violates one of the IT[X] development goals. I've tried to write a simple to use template engine supporting blocks. In contrast to other systems IT[X] analyses the way you've nested blocks and knows which block belongs into another block. The nesting information helps to make the API short and simple. Replacing blocks does not only mean that IT[X] has to update the nesting information (relatively time consumpting task) but you have to make sure that you do not get confused due to the template change itself.


Parameters:

string   $block   —  Blockname
string   $template   —  Blockcontent
boolean   $keep_content   —  true if the new block inherits the content of the old block

[ Top ]

replaceBlockfile   [line 248]

null replaceBlockfile( string $block, string $filename, [boolean $keep_content = false])

Replaces an existing block with new content from a file.
  • Access: public

Parameters:

string   $block   —  Blockname
string   $filename   —  Name of the file that contains the blockcontent
boolean   $keep_content   —  true if the new block inherits the content of the old block

[ Top ]

setCallbackFunction   [line 534]

boolean setCallbackFunction( string $tplfunction, string $callbackfunction, [string $callbackobject = ''], [boolean $expandCallbackParameters = false])

Sets a callback function.

IT[X] templates (note the X) can contain simple function calls. "function call" means that the editor of the template can add special placeholder to the template like 'func_h1("embedded in h1")'. IT[X] will grab this function calls and allow you to define a callback function for them.

This is an absolutely evil feature. If your application makes heavy use of such callbacks and you're even implementing if-then etc. on the level of a template engine you're reiventing the wheel... - that's actually how PHP came into life. Anyway, sometimes it's handy.

Consider also using XML/XSLT or native PHP. And please do not push IT[X] any further into this direction of adding logics to the template engine.

For those of you ready for the X in IT[X]:

<?php ... function h_one($args) { return sprintf('<h1>%s</h1>', $args[0]); }

... $itx = new HTML_Template_ITX(...); ... $itx->setCallbackFunction('h1', 'h_one'); $itx->performCallback(); ?>

template: func_h1('H1 Headline');

  • Return: False on failure.
  • Deprecated: The $callbackobject parameter is depricated since version 1.2 and might be dropped in further versions.
  • Throws: IT_Error
  • Access: public

Parameters:

string   $tplfunction   —  Function name in the template
string   $callbackfunction   —  Name of the callback function
string   $callbackobject   —  Name of the callback object
boolean   $expandCallbackParameters   —  If the callback is called with a list of parameters or with an array holding the parameters

[ Top ]

setCallbackFuntiontable   [line 564]

null setCallbackFuntiontable( array $functions)

Sets the Callback function lookup table
  • Access: public

Parameters:

array   $functions   —  function table array[templatefunction] = array( "function" => userfunction, "object" => userobject )

[ Top ]

setFunctioncontent   [line 480]

null setFunctioncontent( int $functionID, string $replacement)

Replaces a function call with the given replacement.
  • Deprecated:
  • Access: public

Parameters:

int   $functionID   —  Function ID
string   $replacement   —  Replacement

[ Top ]


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