Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

Public Member Functions | Public Attributes | Private Member Functions | List of all members
eZTemplate Class Reference

## Public Member Functions
| __construct ( $templateDir="", $intlDir="", $language="", $phpFile="", $style=false, $module_dir=false, $state=false, $mod_time=false)
| setAllStrings ()
& | cacheFile ()
& | cacheFileName ()
& | cachePath ()
| clearVars ( $except=array())
| hasCache ()
& | cache ()
& | storeCache ( $target, $handle, $print=true)
| clearCache ()
& | ini ()
| set_root ($root)
| set_unknowns ( $unknowns="keep")
| set_file ( $handle, $filename="")
| set_block ( $parent, $handle="", $name="", $required=true)
| set_file_block ( $parent)
| set_var ( $varname, $value="", $substIfEmpty="")
| psubst ( $handle)
& | parse ( $target, $handle="", $append=false)
| pparse ( $target, $handle, $append=false)
& | get_vars ()
& | get_var ( $varname)
| get_user_variable ( $handle, $var)
| get_undefined ($handle)
& | finish ( $str)
| p ( $varname)
| get ( $varname)
| loadfile ( $handle)

## Public Attributes
| $language
| $phpFile
| $intlDir
| $TextStrings
| $Ini
| $debugINI
| $Style
| $ModuleDir
| $State
| $languageFile
| $CacheSuffix
| $CacheDir
| $ExternModTime
| $files = array()
| $file = array()
| $root = ""
| $varkeys = array()
| $varvals = array()
| $unknowns = "remove"
| $halt_on_error = "report"
| $last_error = ""
| $ReplaceFunc

## Private Member Functions
| set_var_internal (&$varname, $value)
& | subst ( $handle)
| filename ( $filename)
| halt ( $msg)
| haltmsg ( $msg)

## Detailed Description

! eZCommon The eZTemplate class provides template functions. In regard to locale information.

This class provides functions for using templates with internationalized language. Template variables which start with intl- are looked up in the language file and replaced with text in the described language.

Handling templates is done by setting the template file, setting up blocks and filling in template variables.

Setting up the template file is done by

$t->set_file( "template_tpl", "template.tpl" );
$t
foreach( $Modules as $module) if(isset( $ItemInsert)) $t
Definition: classes/admin/linklist.php:168

or by using several files

$t->set_file( array( "template_tpl" => "template.tpl",
"second_tpl" => "second.tpl" ) );

If you want to fill in an internationalized language you do

$t->setAllStrings()

all strings are then taken from the language file and supplied as template variables.

Setting up blocks is done by filling in template blocks in the template file

<!-- BEGIN my_block_tpl -->
<b>{my_variable}</b>
<!-- END my_block_tpl -->

and defining them in the template object.

$t->set_block( "template_tpl", "my_block_tpl", "my_block" );

Filling in template variables is either done by setting them directly

$t->set_var( "my_variable", "some text" );

or by parsing a predefined block

$t->parse( "my_block", "my_block_tpl" );
\encode
alternativley parsing a predefined block several times
\code
foreach( $list as $item )
{
$t->set_var( "item", $item );
$t->parse( "my_block", "my_block_tpl", true );
}
\encode
The class can also carry out caching of template content.
Example:
\code
$t->set_file( "template_tpl", "template.tpl" );
if ( $t->hasCache() )
{
print $t->cache();
return;
}
// Do lot's of template stuff
// store the cache and print it
$t->storeCache( "output", "template_tpl" );
eZTemplate\set_file
set_file( $handle, $filename="")
Definition: eztemplate.php:464
eZTemplate\hasCache
hasCache()
Definition: eztemplate.php:311
$item
$item
Definition: classes/admin/linklist.php:228

Definition at line 106 of file eztemplate.php.

## Constructor & Destructor Documentation

## ◆ __construct()

eZTemplate::__construct | ( |  | $templateDir = `""`,
|  |  | $intlDir = `""`,
|  |  | $language = `""`,
|  |  | $phpFile = `""`,
|  |  | $style = `false`,
|  |  | $module_dir = `false`,
|  |  | $state = `false`,
|  |  | $mod_time = `false`
| ) |  |

Constructs a new eZTemplate object.

Definition at line 115 of file eztemplate.php.

References $intlDir, $language, $languageFile, $phpFile, file_exists(), set_root(), and set_unknowns().

## Member Function Documentation

## ◆ cache()

& eZTemplate::cache | ( |  | ) |

If the hasCache() returns true the cache content can be retrieved with this function, otherwise false is returned.

Definition at line 348 of file eztemplate.php.

References $str, cacheFile(), file_exists(), eZPBFile\filesize(), and eZPBFile\fopen().

## ◆ cacheFile()

& eZTemplate::cacheFile | ( |  | ) |

Returns the name of the cache file with path.

Definition at line 261 of file eztemplate.php.

References $CacheSuffix.

Referenced by cache(), clearCache(), hasCache(), and storeCache().

## ◆ cacheFileName()

& eZTemplate::cacheFileName | ( |  | ) |

Returns the name of the cache file.

Definition at line 270 of file eztemplate.php.

References $CacheSuffix.

## ◆ cachePath()

& eZTemplate::cachePath | ( |  | ) |

Returns the path to the cache file.

Definition at line 279 of file eztemplate.php.

References $CacheDir.

## ◆ clearCache()

eZTemplate::clearCache | ( |  | ) |

Clears the cache file if it exists.

Definition at line 399 of file eztemplate.php.

References cacheFile(), file_exists(), and eZPBFile\unlink().

## ◆ clearVars()

eZTemplate::clearVars | ( |  | $except = `array()` | ) |

Clears all template variables except the ones mentioned in the $except variable.

Definition at line 289 of file eztemplate.php.

References $varkeys, and $varvals.

## ◆ filename()

eZTemplate::filename | ( |  | $filename | ) |
| private

Returns a full filepath of the specified filename.

Definition at line 877 of file eztemplate.php.

References $root, file_exists(), and halt().

Referenced by hasCache(), and set_file().

## ◆ finish()

& eZTemplate::finish | ( |  | $str | ) |

Does an operation on the $str depending on what setUnkowns is set too and returns it. If set to: "keep", no change to string "remove", removes all template variables "comment", comments out all template variables "nbsp", changes all template variables into a non-breaking space

See also
  set_unknowns

Definition at line 833 of file eztemplate.php.

References $str.

Referenced by get(), and p().

## ◆ get()

eZTemplate::get | ( |  | $varname | ) |

Returns the content of template variable after it has gone trough finish

See also
  finish(), p()

Definition at line 868 of file eztemplate.php.

References finish(), and get_var().

## ◆ get_undefined()

eZTemplate::get_undefined | ( |  | $handle | ) |

Returns an array of undefined template variables inside another template variable.

Definition at line 798 of file eztemplate.php.

References $result, get_var(), halt(), and loadfile().

## ◆ get_user_variable()

eZTemplate::get_user_variable | ( |  | $handle,
|  |  | $var
| ) |  |

Returns the contents of a template defined variable. You can define variables in the template like this:

This is useful when using override templates and want to define some values just for this template. These variables can be read from the script and override the site.ini settings.

Returns the value if found else false is returned.

Definition at line 784 of file eztemplate.php.

References loadfile().

## ◆ get_var()

& eZTemplate::get_var | ( |  | $varname | ) |

Returns the content of a specific template variable.

Definition at line 745 of file eztemplate.php.

References $result.

Referenced by get(), get_undefined(), p(), parse(), set_block(), and subst().

## ◆ get_vars()

& eZTemplate::get_vars | ( |  | ) |

Returns an array of template variables.

Definition at line 730 of file eztemplate.php.

References $result.

## ◆ halt()

eZTemplate::halt | ( |  | $msg | ) |
| private

Prints out an error message and halts. Whether to print or halt is controlled by the halt_on_error variable.

Definition at line 943 of file eztemplate.php.

References $msg, and haltmsg().

Referenced by filename(), get_undefined(), loadfile(), set_block(), set_file(), set_file_block(), set_root(), and subst().

## ◆ haltmsg()

eZTemplate::haltmsg | ( |  | $msg | ) |
| private

Prints out the halt message

Definition at line 960 of file eztemplate.php.

References eZPBLog\writeNotice().

Referenced by halt().

## ◆ hasCache()

eZTemplate::hasCache | ( |  | ) |

Returns true if the template file has a cache file which can be read, if the cache file does not exist or is too old, false is returned.

Definition at line 311 of file eztemplate.php.

References $lang, cacheFile(), file_exists(), eZPBFile\filemtime(), and filename().

## ◆ ini()

& eZTemplate::ini | ( |  | ) |

Returns a reference to the ini file object.

Definition at line 424 of file eztemplate.php.

References $Ini.

## ◆ loadfile()

eZTemplate::loadfile | ( |  | $handle | ) |

Loads the template file and sets as a template variable.

Definition at line 899 of file eztemplate.php.

References $file, $str, file_exists(), halt(), and set_var_internal().

Referenced by get_undefined(), get_user_variable(), set_block(), set_file_block(), and subst().

## ◆ p()

eZTemplate::p | ( |  | $varname | ) |

Prints out the content of template variable after it has gone trough finish

See also
  finish(), get()

Definition at line 858 of file eztemplate.php.

References finish(), and get_var().

## ◆ parse()

& eZTemplate::parse | ( |  | $target,
|  |  | $handle = `""`,
|  |  | $append = `false`
| ) |  |

Parses a the content of a block into a template variable and returns it. If $target is array treat each key/value as a target and handle. If $handle is array set $target to content of all $handle variables

Definition at line 672 of file eztemplate.php.

References $i, $str, $tmp, get_var(), set_var_internal(), and subst().

Referenced by pparse(), and storeCache().

## ◆ pparse()

eZTemplate::pparse | ( |  | $target,
|  |  | $handle,
|  |  | $append = `false`
| ) |  |

Same as parse() but prints it.

Definition at line 721 of file eztemplate.php.

References parse().

## ◆ psubst()

eZTemplate::psubst | ( |  | $handle | ) |

Same as subst() but prints it.

Definition at line 660 of file eztemplate.php.

References subst().

## ◆ set_block()

eZTemplate::set_block | ( |  | $parent,
|  |  | $handle = `""`,
|  |  | $name = `""`,
|  |  | $required = `true`
| ) |  |

Extract a template block and set it as a template variable, the content of the template variable is the same as the content of the block. If $parent is an array each entry is extracted and set as a block, each entry is assumed to contain a parent, a handle and a name.

Definition at line 501 of file eztemplate.php.

References $name, $phpFile, $str, get_var(), halt(), loadfile(), and set_var_internal().

## ◆ set_file()

eZTemplate::set_file | ( |  | $handle,
|  |  | $filename = `""`
| ) |  |

Sets the file(s) to be working on, its either set to one file with two parameters, set_file( $handle, $filename ), or by several file using an array, set_file( array( "file1_tpl" => "file1.tpl", "file2_tpl" => "file2.tpl" ) );

Definition at line 464 of file eztemplate.php.

References $GlobalSiteIni, $phpFile, filename(), halt(), and set_var().

## ◆ set_file_block()

eZTemplate::set_file_block | ( |  | $parent | ) |

Extract the contents of a file named with set_file and sets it as a template_variable.

Definition at line 546 of file eztemplate.php.

References $file, halt(), and loadfile().

## ◆ set_root()

eZTemplate::set_root | ( |  | $root | ) |

Sets the template directory.

Definition at line 432 of file eztemplate.php.

References $GlobalSiteIni, $root, and halt().

Referenced by __construct().

## ◆ set_unknowns()

eZTemplate::set_unknowns | ( |  | $unknowns = `"keep"` | ) |

Sets what to do with uknown templates variables

Definition at line 453 of file eztemplate.php.

References $unknowns.

Referenced by __construct().

## ◆ set_var()

eZTemplate::set_var | ( |  | $varname,
|  |  | $value = `""`,
|  |  | $substIfEmpty = `""`
| ) |  |

Sets a template variable to contain a certain value. If $value is an empty string the contents will be replaced with the contents of $subsIfEmtpy (which also is empty as default)

Definition at line 577 of file eztemplate.php.

References set_var_internal().

Referenced by set_file().

## ◆ set_var_internal()

eZTemplate::set_var_internal | ( | & | $varname,
|  |  | $value
| ) |  |
| private

Sets the template variable using references.

Definition at line 589 of file eztemplate.php.

Referenced by loadfile(), parse(), set_block(), set_var(), and setAllStrings().

## ◆ setAllStrings()

eZTemplate::setAllStrings | ( |  | ) |

Sets all internationalisations.

Definition at line 243 of file eztemplate.php.

References $i, $tmp, and set_var_internal().

## ◆ storeCache()

& eZTemplate::storeCache | ( |  | $target,
|  |  | $handle,
|  |  | $print = `true`
| ) |  |

Instead of using pparse for printing out the template, one can use this to store the template content to a cache file and eventually print it. If $print is true the template content is printed.

Definition at line 370 of file eztemplate.php.

References $str, cacheFile(), file_exists(), eZPBFile\fopen(), and parse().

## ◆ subst()

& eZTemplate::subst | ( |  | $handle | ) |
| private

Retrieves a template variable and subsistutes all variable in that with all defined template variables and returns it.

Definition at line 630 of file eztemplate.php.

References $ReplaceFunc, $str, get_var(), halt(), and loadfile().

Referenced by parse(), and psubst().

## Member Data Documentation

## ◆ $CacheDir

eZTemplate::$CacheDir

Definition at line 981 of file eztemplate.php.

Referenced by cachePath().

## ◆ $CacheSuffix

eZTemplate::$CacheSuffix

Definition at line 980 of file eztemplate.php.

Referenced by cacheFile(), and cacheFileName().

## ◆ $debugINI

eZTemplate::$debugINI

Definition at line 975 of file eztemplate.php.

## ◆ $ExternModTime

eZTemplate::$ExternModTime

Definition at line 982 of file eztemplate.php.

## ◆ $file

eZTemplate::$file = array()

Definition at line 987 of file eztemplate.php.

Referenced by loadfile(), and set_file_block().

## ◆ $files

eZTemplate::$files = array()

Definition at line 984 of file eztemplate.php.

## ◆ $halt_on_error

eZTemplate::$halt_on_error = "report"

Definition at line 1004 of file eztemplate.php.

## ◆ $Ini

eZTemplate::$Ini

Definition at line 974 of file eztemplate.php.

Referenced by ini().

## ◆ $intlDir

eZTemplate::$intlDir

Definition at line 110 of file eztemplate.php.

Referenced by __construct().

## ◆ $language

eZTemplate::$language

Definition at line 108 of file eztemplate.php.

Referenced by __construct().

## ◆ $languageFile

eZTemplate::$languageFile

Definition at line 979 of file eztemplate.php.

Referenced by __construct().

## ◆ $last_error

eZTemplate::$last_error = ""

Definition at line 1007 of file eztemplate.php.

## ◆ $ModuleDir

eZTemplate::$ModuleDir

Definition at line 977 of file eztemplate.php.

## ◆ $phpFile

eZTemplate::$phpFile

Definition at line 109 of file eztemplate.php.

Referenced by __construct(), set_block(), and set_file().

## ◆ $ReplaceFunc

eZTemplate::$ReplaceFunc

Definition at line 1009 of file eztemplate.php.

Referenced by subst().

## ◆ $root

eZTemplate::$root = ""

Definition at line 990 of file eztemplate.php.

Referenced by filename(), and set_root().

## ◆ $State

eZTemplate::$State

Definition at line 978 of file eztemplate.php.

## ◆ $Style

eZTemplate::$Style

Definition at line 976 of file eztemplate.php.

## ◆ $TextStrings

eZTemplate::$TextStrings

Definition at line 973 of file eztemplate.php.

## ◆ $unknowns

eZTemplate::$unknowns = "remove"

Definition at line 1001 of file eztemplate.php.

Referenced by set_unknowns().

## ◆ $varkeys

eZTemplate::$varkeys = array()

Definition at line 993 of file eztemplate.php.

Referenced by clearVars().

## ◆ $varvals

eZTemplate::$varvals = array()

Definition at line 994 of file eztemplate.php.

Referenced by clearVars().

The documentation for this class was generated from the following file:

- eztemplate.php

Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.