fTemplatingclassv1.0.0b2

Allows for quick and flexible HTML templating

Changes:
1.0.0b2Added the inject() method 1/9/09
1.0.0bThe initial implementation 6/14/07

Variables

->rootprotected

The directory to look for files

Type

string

Methods

->__construct() public

Initializes this templating engine

Signature

fTemplating __construct( string $root=NULL )

Parameters

string $root The filesystem path to use when accessing relative files, defaults to $_SERVER['DOCUMENT_ROOT']

->__destruct() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Finishing placing elements if buffering was used

Signature

void __destruct( )

->__get() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

All requests that hit this method should be requests for callbacks

Signature

callback __get( string $method )

Parameters

string $method The method to create a callback for

Returns

The callback for the method requested

->add() public

Adds a value to an array element

Signature

void add( string $element, mixed $value )

Parameters

string $element The element to add to
mixed $value The value to add

->buffer() public

Enables buffered output, allowing set() and add() to happen after a place() but act as if they were done before

Please note that using buffered output will affect the order in which code is executed since the elements are not actually place()'ed until the destructor is called.

If the non-template code depends on template code being executed sequentially before it, you may not want to use output buffering.

Signature

void buffer( )

->destroy() public

Erases all output since the invocation of the template - only works if buffering is on

Signature

void destroy( )

->get() public

Gets the value of an element

Signature

mixed get( string $element, mixed $default_value=NULL )

Parameters

string $element The element to get
mixed $default_value The value to return if the element has not been set

Returns

The value of the element specified, or the default value if it has not been set

->inject() public

Includes the file specified - this is identical to place() except a filename is specified instead of an element

Please see the place() method for more details about functionality.

Signature

void inject( string $file_path, string $file_type=NULL )

Parameters

string $file_path The file to place
string $file_type Will force the file to be placed as this type of file instead of auto-detecting the file type. Valid types include: 'css', 'js', 'php' and 'rss'.

->place() public

Includes the element specified - element must be set through set() first

If the element is a file path ending in .css, .js, .rss or .xml an appropriate HTML tag will be printed (files ending in .xml will be treated as an RSS feed). If the element is a file path ending in .inc, .php or .php5 it will be included.

Paths that start with ./ will be loaded relative to the current script. Paths that start with a file or directory name will be loaded relative to the $root passed in the constructor. Paths that start with / will be loaded from the root of the filesystem.

You can pass the media attribute of a CSS file or the title attribute of an RSS feed by adding an associative array with the following formats:

array(
    'path'  => (string) {css file path},
    'media' => (string) {media type}
);
array(
    'path'  => (string) {rss file path},
    'title' => (string) {feed title}
);

Signature

void place( string $element, string $file_type=NULL )

Parameters

string $element The element to place
string $file_type Will force the element to be placed as this type of file instead of auto-detecting the file type. Valid types include: 'css', 'js', 'php' and 'rss'.

->placeCSS() protected

Prints a CSS link HTML tag to the output

Signature

void placeCSS( mixed $info )

Parameters

mixed $info The path or array containing the 'path' to the CSS file. Array can also contain a key 'media'.

->placeElement() protected

Performs the action of actually placing an element

Signature

void placeElement( string $element, string $file_type )

Parameters

string $element The element that is being placed
string $file_type The file type to treat all values as

->placeJS() protected

Prints a javascript HTML tag to the output

Signature

void placeJS( mixed $info )

Parameters

mixed $info The path or array containing the 'path' to the javascript file

->placePHP() protected

Includes a PHP file

Signature

void placePHP( string $element, string $path )

Parameters

string $element The element being placed
string $path The path to the PHP file

->placeRSS() protected

Prints an RSS link HTML tag to the output

Signature

void placeRSS( mixed $info )

Parameters

mixed $info The path or array containing the 'path' to the RSS xml file. May also contain a 'title' key for the title of the RSS feed.

->prepare() public

Gets the value of an element and runs it through fHTML::prepare()

Signature

mixed prepare( string $element, mixed $default_value=NULL )

Parameters

string $element The element to get
mixed $default_value The value to return if the element has not been set

Returns

The value of the element specified run through fHTML::prepare(), or the default value if it has not been set

->set() public

Sets the value for an element

Signature

void set( string $element, mixed $value )

Parameters

string $element The element to set
mixed $value The value for the element

->verifyValue() protected

Ensures the value is valid

Signature

string verifyValue( string $element, mixed $value, string $file_type=NULL )

Parameters

string $element The element that is being placed
mixed $value A value to be placed
string $file_type The file type that this element will be displayed as - skips checking file extension

Returns

The file type of the value being placed