create an instance
SmartTemplate
SmartTemplate
(
[string $filename = ""]
)
List of parameters:
Name |
Type |
Description |
$filename |
string |
(optional) |
Description:
You may enter a filename of a template you want to use.
compare with another object
string
equals
(
object $anotherObject
)
List of parameters:
Name |
Type |
Description |
$anotherObject |
object |
|
Description:
Returns bool(true) if this object and $anotherObject are equal and bool(false) otherwise.
Two instances are considered equal if and only if they are both objects of the same class and they both refer to the same filesystem resource.
Redefinition of: Object::equals()
fetch a template or template var
mixed
get
(
[string $key = null], [bool $overwrite = true]
)
List of parameters:
Name |
Type |
Description |
$key |
string |
variable-name |
$overwrite |
bool |
true = on / false = off |
Description:
There are three ways to call this function:
If you call $smartTemplate->get($varName) it will get the template var $varName and return it.
If you call $smartTemplate->get("*") with the wildcard '*' or an empty string '' it will return an associative array containing all template vars.
If you call $smartTemplate->get() without a parameter it will fetch the current template and return it as a string.
If the $key parameter is NULL, the second parameter can be used to change the way how variables are imported from the global registry to the template. If set to false, existing template vars will not be replaced by vars of the same name in the registry. Otherwise template vars will get overwritten if the global registry has another value.
get path and name of current template
string
getPath
()
Description:
Returns a string containing the path and filename of the current template relative to the framework's home directory.
bypass template class
Smarty
&getSmarty
()
Description:
This function is used to unbox the smarty instance inside the object. It may be used to bypass the template class in cases where direct access to the smarty template engine is necessary.
assign a variable by value
bool
insert
(
string $varName, mixed $var
)
List of parameters:
Name |
Type |
Description |
$varName |
string |
address |
$var |
mixed |
some new value |
Description:
This assigns the $var to the name $varName.
Unlike Smarty's "assign()" this function takes an additional value for $varName:
You may use the wildcard '*' to merge an associative array with the template vars. Example of usage:
$smartTemplate->insert('*', array $var)
Returns bool(true) on success and bool(false) on error.
assign a variable by reference
bool
insertByReference
(
string $varName, mixed &$var
)
List of parameters:
Name |
Type |
Description |
$varName |
string |
address |
&$var |
mixed |
some new value |
Description:
This assigns the $var to the name $varName.
Unlike Smarty's "assign()" this function takes an additional value for $varName:
You may use the wildcard '*' to merge an associative array with the template vars.
insert a file
bool
insertFile
(
string $varName, string $filename
)
List of parameters:
Name |
Type |
Description |
$varName |
string |
|
$filename |
string |
|
Description:
Load a file and assign it's content as a string to the provided template var.
Returns bool(true) on success and bool(false) on error.
Register function
bool
setFunction
(
int $as, string $name, mixed $code
)
List of parameters:
Name |
Type |
Description |
$as |
int |
one of: YANA_TPL_FUNCTION, YANA_TPL_MODIFIER, YANA_TPL_BLOCK |
$name |
string |
name of the function |
$code |
mixed |
a callable resource |
Description:
This function registers the function at $code as a template function under the name $name in the template engine.
Argument $as can be one of the followin constants:
- YANA_TPL_FUNCTION
- registers the resource as a template function,
called as [%foo %]
- YANA_TPL_MODIFIER
- registers the resource as a template modifier,
called as [%$bar|foo%]
- YANA_TPL_BLOCK
- registers the resource as a template block function,
called as [%foo %]...[%/foo%]
Argument $name:
- Say, you register some function as YANA_TPL_FUNCTION under the name "foo",
then you can call this function from within a template using: [%foo %]
Argument $code:
- Say, you got a PHP function like foo().
To refer to this function use the code-argument with the string
"foo".
- Say, you got a PHP class "Foo" and a static function "bar",
which you would call from PHP as Foo::bar().
To refer to this function use the code-argument with the array
array("Foo", "bar").
- Say, you got a PHP object $foo and a non-static function "bar",
which you would call from PHP as $foo->bar().
To refer to this function use the code-argument with the array
array($foo, "bar").
Note: For details on how the called function should look like, see the smarty documentation at http://smarty.php.net/docs.php, chapter 16) "Extending smarty", sections: "template functions", "modifiers" and "block functions".
set filename of current template
bool
setPath
(
string $filename
)
List of parameters:
Name |
Type |
Description |
$filename |
string |
name of the template file |
Description:
You may set another filename of a template to fetch.
Please note:
- Template files may not have a reserved extension like
"htaccess", "php", "config" or the like.
- Files should be adressed from the root.
This is where "index.php" is stored.
- If you can't access a file, the file does not exist
or is not readable, a template error is thrown.
- Filenames are case-sensitive!
Unregister function
bool
unsetFunction
(
int $as, string $name
)
List of parameters:
Name |
Type |
Description |
$as |
int |
one of: YANA_TPL_FUNCTION, YANA_TPL_MODIFIER, YANA_TPL_BLOCK |
$name |
string |
name of the function |
Description:
By using this, the function named $name will no longer be available in template. Be cautious: If the unregistered funciton is still used inside the template, this will issue a template error and possibly cause your application to exit.
output the template to screen
void
write
()
Description:
This function will fetch and print the current template to the screen.
inherited from base classes
Inherited From Object