mirror of
https://github.com/smarty-php/smarty.git
synced 2025-07-29 23:47:15 +02:00
Feature/add docs (#689)
* Add converted docs repo * Set theme jekyll-theme-minimal * Removed BC docs, added TOC * Added TOCs, rewrote most important links in documentation. Linked README to new Github Pages site * some link fixes
This commit is contained in:
49
docs/programmers/api-functions/api-add-config-dir.md
Normal file
49
docs/programmers/api-functions/api-add-config-dir.md
Normal file
@ -0,0 +1,49 @@
|
||||
addConfigDir()
|
||||
|
||||
add a directory to the list of directories where config files are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
Smarty
|
||||
|
||||
addConfigDir
|
||||
|
||||
string\|array
|
||||
|
||||
config\_dir
|
||||
|
||||
string
|
||||
|
||||
key
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// add directory where config files are stored
|
||||
$smarty->addConigDir('./config_1');
|
||||
|
||||
// add directory where config files are stored and specify array-key
|
||||
$smarty->addConfigDir('./config_1', 'one');
|
||||
|
||||
// add multiple directories where config files are stored and specify array-keys
|
||||
$smarty->addTemplateDir(array(
|
||||
'two' => './config_2',
|
||||
'three' => './config_3',
|
||||
));
|
||||
|
||||
// view the template dir chain
|
||||
var_dump($smarty->getConfigDir());
|
||||
|
||||
// chaining of method calls
|
||||
$smarty->setConfigDir('./config')
|
||||
->addConfigDir('./config_1', 'one')
|
||||
->addConfigDir('./config_2', 'two');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`getConfigDir()`](#api.get.config.dir),
|
||||
[`setConfigDir()`](#api.set.config.dir) and
|
||||
[`$config_dir`](#variable.config.dir).
|
42
docs/programmers/api-functions/api-add-plugins-dir.md
Normal file
42
docs/programmers/api-functions/api-add-plugins-dir.md
Normal file
@ -0,0 +1,42 @@
|
||||
addPluginsDir()
|
||||
|
||||
add a directory to the list of directories where plugins are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
Smarty
|
||||
|
||||
addPluginsDir
|
||||
|
||||
string\|array
|
||||
|
||||
plugins\_dir
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// add directory where plugins are stored
|
||||
$smarty->addPluginsDir('./plugins_1');
|
||||
|
||||
// add multiple directories where plugins are stored
|
||||
$smarty->setPluginsDir(array(
|
||||
'./plugins_2',
|
||||
'./plugins_3',
|
||||
));
|
||||
|
||||
// view the plugins dir chain
|
||||
var_dump($smarty->getPluginsDir());
|
||||
|
||||
// chaining of method calls
|
||||
$smarty->setPluginsDir('./plugins')
|
||||
->addPluginsDir('./plugins_1')
|
||||
->addPluginsDir('./plugins_2');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`getPluginsDir()`](#api.get.plugins.dir),
|
||||
[`setPluginsDir()`](#api.set.plugins.dir) and
|
||||
[`$plugins_dir`](#variable.plugins.dir).
|
49
docs/programmers/api-functions/api-add-template-dir.md
Normal file
49
docs/programmers/api-functions/api-add-template-dir.md
Normal file
@ -0,0 +1,49 @@
|
||||
addTemplateDir()
|
||||
|
||||
add a directory to the list of directories where templates are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
Smarty
|
||||
|
||||
addTemplateDir
|
||||
|
||||
string\|array
|
||||
|
||||
template\_dir
|
||||
|
||||
string
|
||||
|
||||
key
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// add directory where templates are stored
|
||||
$smarty->addTemplateDir('./templates_1');
|
||||
|
||||
// add directory where templates are stored and specify array-key
|
||||
$smarty->addTemplateDir('./templates_1', 'one');
|
||||
|
||||
// add multiple directories where templates are stored and specify array-keys
|
||||
$smarty->addTemplateDir(array(
|
||||
'two' => './templates_2',
|
||||
'three' => './templates_3',
|
||||
));
|
||||
|
||||
// view the template dir chain
|
||||
var_dump($smarty->getTemplateDir());
|
||||
|
||||
// chaining of method calls
|
||||
$smarty->setTemplateDir('./templates')
|
||||
->addTemplateDir('./templates_1', 'one')
|
||||
->addTemplateDir('./templates_2', 'two');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`getTemplateDir()`](#api.get.template.dir),
|
||||
[`setTemplateDir()`](#api.set.template.dir) and
|
||||
[`$template_dir`](#variable.template.dir).
|
46
docs/programmers/api-functions/api-append-by-ref.md
Normal file
46
docs/programmers/api-functions/api-append-by-ref.md
Normal file
@ -0,0 +1,46 @@
|
||||
appendByRef()
|
||||
|
||||
append values by reference
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
appendByRef
|
||||
|
||||
string
|
||||
|
||||
varname
|
||||
|
||||
mixed
|
||||
|
||||
var
|
||||
|
||||
bool
|
||||
|
||||
merge
|
||||
|
||||
This is used to [`append()`](#api.append) values to the templates by
|
||||
reference.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> With the introduction of PHP5, `appendByRef()` is not necessary for
|
||||
> most intents and purposes. `appendByRef()` is useful if you want a PHP
|
||||
> array index value to be affected by its reassignment from a template.
|
||||
> Assigned object properties behave this way by default.
|
||||
|
||||
NOTE.PARAMETER.MERGE
|
||||
|
||||
|
||||
<?php
|
||||
// appending name/value pairs
|
||||
$smarty->appendByRef('Name', $myname);
|
||||
$smarty->appendByRef('Address', $address);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`append()`](#api.append), [`assign()`](#api.assign) and
|
||||
[`getTemplateVars()`](#api.get.template.vars).
|
61
docs/programmers/api-functions/api-append.md
Normal file
61
docs/programmers/api-functions/api-append.md
Normal file
@ -0,0 +1,61 @@
|
||||
append()
|
||||
|
||||
append an element to an assigned array
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
append
|
||||
|
||||
mixed
|
||||
|
||||
var
|
||||
|
||||
void
|
||||
|
||||
append
|
||||
|
||||
string
|
||||
|
||||
varname
|
||||
|
||||
mixed
|
||||
|
||||
var
|
||||
|
||||
bool
|
||||
|
||||
merge
|
||||
|
||||
If you append to a string value, it is converted to an array value and
|
||||
then appended to. You can explicitly pass name/value pairs, or
|
||||
associative arrays containing the name/value pairs. If you pass the
|
||||
optional third parameter of TRUE, the value will be merged with the
|
||||
current array instead of appended.
|
||||
|
||||
NOTE.PARAMETER.MERGE
|
||||
|
||||
|
||||
<?php
|
||||
// This is effectively the same as assign()
|
||||
$smarty->append('foo', 'Fred');
|
||||
// After this line, foo will now be seen as an array in the template
|
||||
$smarty->append('foo', 'Albert');
|
||||
|
||||
$array = array(1 => 'one', 2 => 'two');
|
||||
$smarty->append('X', $array);
|
||||
$array2 = array(3 => 'three', 4 => 'four');
|
||||
// The following line will add a second element to the X array
|
||||
$smarty->append('X', $array2);
|
||||
|
||||
// passing an associative array
|
||||
$smarty->append(array('city' => 'Lincoln', 'state' => 'Nebraska'));
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`appendByRef()`](#api.append.by.ref),
|
||||
[`assign()`](#api.assign) and
|
||||
[`getTemplateVars()`](#api.get.template.vars)
|
42
docs/programmers/api-functions/api-assign-by-ref.md
Normal file
42
docs/programmers/api-functions/api-assign-by-ref.md
Normal file
@ -0,0 +1,42 @@
|
||||
assignByRef()
|
||||
|
||||
assign values by reference
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
assignByRef
|
||||
|
||||
string
|
||||
|
||||
varname
|
||||
|
||||
mixed
|
||||
|
||||
var
|
||||
|
||||
This is used to [`assign()`](#api.assign) values to the templates by
|
||||
reference.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> With the introduction of PHP5, `assignByRef()` is not necessary for
|
||||
> most intents and purposes. `assignByRef()` is useful if you want a PHP
|
||||
> array index value to be affected by its reassignment from a template.
|
||||
> Assigned object properties behave this way by default.
|
||||
|
||||
|
||||
<?php
|
||||
// passing name/value pairs
|
||||
$smarty->assignByRef('Name', $myname);
|
||||
$smarty->assignByRef('Address', $address);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`assign()`](#api.assign),
|
||||
[`clearAllAssign()`](#api.clear.all.assign), [`append()`](#api.append),
|
||||
[`{assign}`](#language.function.assign) and
|
||||
[`getTemplateVars()`](#api.get.template.vars).
|
84
docs/programmers/api-functions/api-assign.md
Normal file
84
docs/programmers/api-functions/api-assign.md
Normal file
@ -0,0 +1,84 @@
|
||||
assign()
|
||||
|
||||
assign variables/objects to the templates
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
assign
|
||||
|
||||
mixed
|
||||
|
||||
var
|
||||
|
||||
void
|
||||
|
||||
assign
|
||||
|
||||
string
|
||||
|
||||
varname
|
||||
|
||||
mixed
|
||||
|
||||
var
|
||||
|
||||
bool
|
||||
|
||||
nocache
|
||||
|
||||
You can explicitly pass name/value pairs, or associative arrays
|
||||
containing the name/value pairs.
|
||||
|
||||
If you pass the optional third `nocache` parameter of TRUE, the variable
|
||||
is assigned as nocache variable. See
|
||||
[`Cacheability of Variables`](#cacheability.variables) for details.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> When you assign/register objects to templates, be sure that all
|
||||
> properties and methods accessed from the template are for presentation
|
||||
> purposes only. It is very easy to inject application logic through
|
||||
> objects, and this leads to poor designs that are difficult to manage.
|
||||
> See the Best Practices section of the Smarty website.
|
||||
|
||||
|
||||
<?php
|
||||
// passing name/value pairs
|
||||
$smarty->assign('Name', 'Fred');
|
||||
$smarty->assign('Address', $address);
|
||||
|
||||
// passing an associative array
|
||||
$smarty->assign(array('city' => 'Lincoln', 'state' => 'Nebraska'));
|
||||
|
||||
// passing an array
|
||||
$myArray = array('no' => 10, 'label' => 'Peanuts');
|
||||
$smarty->assign('foo',$myArray);
|
||||
|
||||
// passing a row from a database (eg adodb)
|
||||
$sql = 'select id, name, email from contacts where contact ='.$id;
|
||||
$smarty->assign('contact', $db->getRow($sql));
|
||||
?>
|
||||
|
||||
These are accessed in the template with
|
||||
|
||||
|
||||
{* note the vars are case sensitive like php *}
|
||||
{$Name}
|
||||
{$Address}
|
||||
{$city}
|
||||
{$state}
|
||||
|
||||
{$foo.no}, {$foo.label}
|
||||
{$contact.id}, {$contact.name},{$contact.email}
|
||||
|
||||
To access more complex array assignments see
|
||||
[`{foreach}`](#language.function.foreach) and
|
||||
[`{section}`](#language.function.section)
|
||||
|
||||
See also [`assignByRef()`](#api.assign.by.ref),
|
||||
[`getTemplateVars()`](#api.get.template.vars),
|
||||
[`clearAssign()`](#api.clear.assign), [`append()`](#api.append) and
|
||||
[`{assign}`](#language.function.assign)
|
34
docs/programmers/api-functions/api-clear-all-assign.md
Normal file
34
docs/programmers/api-functions/api-clear-all-assign.md
Normal file
@ -0,0 +1,34 @@
|
||||
clearAllAssign()
|
||||
|
||||
clears the values of all assigned variables
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
clearAllAssign
|
||||
|
||||
|
||||
<?php
|
||||
// passing name/value pairs
|
||||
$smarty->assign('Name', 'Fred');
|
||||
$smarty->assign('Address', $address);
|
||||
|
||||
// will output above
|
||||
print_r( $smarty->getTemplateVars() );
|
||||
|
||||
// clear all assigned variables
|
||||
$smarty->clearAllAssign();
|
||||
|
||||
// will output nothing
|
||||
print_r( $smarty->getTemplateVars() );
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`clearAssign()`](#api.clear.assign),
|
||||
[`clearConfig()`](#api.clear.config),
|
||||
[`getTemplateVars()`](#api.get.template.vars), [`assign()`](#api.assign)
|
||||
and [`append()`](#api.append)
|
37
docs/programmers/api-functions/api-clear-all-cache.md
Normal file
37
docs/programmers/api-functions/api-clear-all-cache.md
Normal file
@ -0,0 +1,37 @@
|
||||
clearAllCache()
|
||||
|
||||
clears the entire template cache
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
clearAllCache
|
||||
|
||||
int
|
||||
|
||||
expire\_time
|
||||
|
||||
As an optional parameter, you can supply a minimum age in seconds the
|
||||
cache files must be before they will get cleared.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Since Smarty version 3.1.14 it is possible to delete cache files by
|
||||
> their individual expiration time at creation by passing constant
|
||||
> SMARTY::CLEAR\_EXPIRED as `expire_time` parameter.
|
||||
|
||||
|
||||
<?php
|
||||
// clear the entire cache
|
||||
$smarty->clearAllCache();
|
||||
|
||||
// clears all files over one hour old
|
||||
$smarty->clearAllCache(3600);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`clearCache()`](#api.clear.cache),
|
||||
[`isCached()`](#api.is.cached) and the [caching](#caching) page.
|
32
docs/programmers/api-functions/api-clear-assign.md
Normal file
32
docs/programmers/api-functions/api-clear-assign.md
Normal file
@ -0,0 +1,32 @@
|
||||
clearAssign()
|
||||
|
||||
clears the value of an assigned variable
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
clearAssign
|
||||
|
||||
mixed
|
||||
|
||||
var
|
||||
|
||||
This can be a single value, or an array of values.
|
||||
|
||||
|
||||
<?php
|
||||
// clear a single variable
|
||||
$smarty->clearAssign('Name');
|
||||
|
||||
// clears multiple variables
|
||||
$smarty->clearAssign(array('Name', 'Address', 'Zip'));
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`clearAllAssign()`](#api.clear.all.assign),
|
||||
[`clearConfig()`](#api.clear.config),
|
||||
[`getTemplateVars()`](#api.get.template.vars), [`assign()`](#api.assign)
|
||||
and [`append()`](#api.append)
|
60
docs/programmers/api-functions/api-clear-cache.md
Normal file
60
docs/programmers/api-functions/api-clear-cache.md
Normal file
@ -0,0 +1,60 @@
|
||||
clearCache()
|
||||
|
||||
clears the cache for a specific template
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
clearCache
|
||||
|
||||
string
|
||||
|
||||
template
|
||||
|
||||
string
|
||||
|
||||
cache\_id
|
||||
|
||||
string
|
||||
|
||||
compile\_id
|
||||
|
||||
int
|
||||
|
||||
expire\_time
|
||||
|
||||
- If you have [multiple caches](#caching.multiple.caches) for a
|
||||
template, you can clear a specific cache by supplying the `cache_id`
|
||||
as the second parameter.
|
||||
|
||||
- You can also pass a [`$compile_id`](#variable.compile.id) as a third
|
||||
parameter. You can [group templates together](#caching.groups) so
|
||||
they can be removed as a group, see the [caching section](#caching)
|
||||
for more information.
|
||||
|
||||
- As an optional fourth parameter, you can supply a minimum age in
|
||||
seconds the cache file must be before it will get cleared.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Since Smarty version 3.1.14 it is possible to delete cache files
|
||||
> by their individual expiration time at creation by passing
|
||||
> constant SMARTY::CLEAR\_EXPIRED as fourth parameter.
|
||||
|
||||
<!-- -->
|
||||
|
||||
|
||||
<?php
|
||||
// clear the cache for a template
|
||||
$smarty->clearCache('index.tpl');
|
||||
|
||||
// clear the cache for a particular cache id in an multiple-cache template
|
||||
$smarty->clearCache('index.tpl', 'MY_CACHE_ID');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`clearAllCache()`](#api.clear.all.cache) and
|
||||
[`caching`](#caching) section.
|
44
docs/programmers/api-functions/api-clear-compiled-tpl.md
Normal file
44
docs/programmers/api-functions/api-clear-compiled-tpl.md
Normal file
@ -0,0 +1,44 @@
|
||||
clearCompiledTemplate()
|
||||
|
||||
clears the compiled version of the specified template resource
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
clearCompiledTemplate
|
||||
|
||||
string
|
||||
|
||||
tpl\_file
|
||||
|
||||
string
|
||||
|
||||
compile\_id
|
||||
|
||||
int
|
||||
|
||||
exp\_time
|
||||
|
||||
This clears the compiled version of the specified template resource, or
|
||||
all compiled template files if one is not specified. If you pass a
|
||||
[`$compile_id`](#variable.compile.id) only the compiled template for
|
||||
this specific [`$compile_id`](#variable.compile.id) is cleared. If you
|
||||
pass an exp\_time, then only compiled templates older than `exp_time`
|
||||
seconds are cleared, by default all compiled templates are cleared
|
||||
regardless of their age. This function is for advanced use only, not
|
||||
normally needed.
|
||||
|
||||
|
||||
<?php
|
||||
// clear a specific template resource
|
||||
$smarty->clearCompiledTemplate('index.tpl');
|
||||
|
||||
// clear entire compile directory
|
||||
$smarty->clearCompiledTemplate();
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`clearCache()`](#api.clear.cache).
|
35
docs/programmers/api-functions/api-clear-config.md
Normal file
35
docs/programmers/api-functions/api-clear-config.md
Normal file
@ -0,0 +1,35 @@
|
||||
clearConfig()
|
||||
|
||||
clears assigned config variables
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
clearConfig
|
||||
|
||||
string
|
||||
|
||||
var
|
||||
|
||||
This clears all assigned [config variables](#language.config.variables).
|
||||
If a variable name is supplied, only that variable is cleared.
|
||||
|
||||
|
||||
<?php
|
||||
// clear all assigned config variables.
|
||||
$smarty->clearConfig();
|
||||
|
||||
// clear one variable
|
||||
$smarty->clearConfig('foobar');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`getConfigVars()`](#api.get.config.vars),
|
||||
[`config variables`](#language.config.variables),
|
||||
[`config files`](#config.files),
|
||||
[`{config_load}`](#language.function.config.load),
|
||||
[`configLoad()`](#api.config.load) and
|
||||
[`clearAssign()`](#api.clear.assign).
|
61
docs/programmers/api-functions/api-compile-all-config.md
Normal file
61
docs/programmers/api-functions/api-compile-all-config.md
Normal file
@ -0,0 +1,61 @@
|
||||
compileAllConfig()
|
||||
|
||||
compiles all known config files
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
compileAllConfig
|
||||
|
||||
string
|
||||
|
||||
extension
|
||||
|
||||
boolean
|
||||
|
||||
force
|
||||
|
||||
integer
|
||||
|
||||
timelimit
|
||||
|
||||
integer
|
||||
|
||||
maxerror
|
||||
|
||||
This function compiles config files found in the
|
||||
[`$config_dir`](#variable.config.dir) folder. It uses the following
|
||||
parameters:
|
||||
|
||||
- `extension` is an optional string which defines the file extension
|
||||
for the config files. The default is \".conf\".
|
||||
|
||||
- `force` is an optional boolean which controls if only modified
|
||||
(false) or all (true) config files shall be compiled. The default is
|
||||
\"false\".
|
||||
|
||||
- `timelimit` is an optional integer to set a runtime limit in seconds
|
||||
for the compilation process. The default is no limit.
|
||||
|
||||
- `maxerror` is an optional integer to set an error limit. If more
|
||||
config files failed to compile the function will be aborted. The
|
||||
default is no limit.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> This function may not create desired results in all configurations.
|
||||
> Use is on own risk.
|
||||
|
||||
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
|
||||
// force compilation of all config files
|
||||
$smarty->compileAllConfig('.config',true);
|
||||
|
||||
?>
|
||||
|
||||
|
71
docs/programmers/api-functions/api-compile-all-templates.md
Normal file
71
docs/programmers/api-functions/api-compile-all-templates.md
Normal file
@ -0,0 +1,71 @@
|
||||
compileAllTemplates()
|
||||
|
||||
compiles all known templates
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
compileAllTemplates
|
||||
|
||||
string
|
||||
|
||||
extension
|
||||
|
||||
boolean
|
||||
|
||||
force
|
||||
|
||||
integer
|
||||
|
||||
timelimit
|
||||
|
||||
integer
|
||||
|
||||
maxerror
|
||||
|
||||
This function compiles template files found in the
|
||||
[`$template_dir`](#variable.template.dir) folder. It uses the following
|
||||
parameters:
|
||||
|
||||
- `extension` is an optional string which defines the file extension
|
||||
for the template files. The default is \".tpl\".
|
||||
|
||||
- `force` is an optional boolean which controls if only modified
|
||||
(false) or all (true) templates shall be compiled. The default is
|
||||
\"false\".
|
||||
|
||||
- `timelimit` is an optional integer to set a runtime limit in seconds
|
||||
for the compilation process. The default is no limit.
|
||||
|
||||
- `maxerror` is an optional integer to set an error limit. If more
|
||||
templates failed to compile the function will be aborted. The
|
||||
default is no limit.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> This function may not create desired results in all configurations.
|
||||
> Use is on own risk.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> If any template requires registered plugins, filters or objects you
|
||||
> must register all of them before running this function.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> If you are using template inheritance this function will create
|
||||
> compiled files of parent templates which will never be used.
|
||||
|
||||
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
|
||||
// force compilation of all template files
|
||||
$smarty->compileAllTemplates('.tpl',true);
|
||||
|
||||
?>
|
||||
|
||||
|
47
docs/programmers/api-functions/api-config-load.md
Normal file
47
docs/programmers/api-functions/api-config-load.md
Normal file
@ -0,0 +1,47 @@
|
||||
configLoad()
|
||||
|
||||
loads config file data and assigns it to the template
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
configLoad
|
||||
|
||||
string
|
||||
|
||||
file
|
||||
|
||||
string
|
||||
|
||||
section
|
||||
|
||||
This loads [config file](#config.files) data and assigns it to the
|
||||
template. This works identically to the template
|
||||
[`{config_load}`](#language.function.config.load) function.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> As of Smarty 2.4.0, assigned template variables are kept across
|
||||
> invocations of [`fetch()`](#api.fetch) and
|
||||
> [`display()`](#api.display). Config vars loaded from `configLoad()`
|
||||
> are always global in scope. Config files are also compiled for faster
|
||||
> execution, and respect the [`$force_compile`](#variable.force.compile)
|
||||
> and [`$compile_check`](#variable.compile.check) settings.
|
||||
|
||||
|
||||
<?php
|
||||
// load config variables and assign them
|
||||
$smarty->configLoad('my.conf');
|
||||
|
||||
// load a section
|
||||
$smarty->configLoad('my.conf', 'foobar');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`{config_load}`](#language.function.config.load),
|
||||
[`getConfigVars()`](#api.get.config.vars),
|
||||
[`clearConfig()`](#api.clear.config), and
|
||||
[`config variables`](#language.config.variables)
|
52
docs/programmers/api-functions/api-create-data.md
Normal file
52
docs/programmers/api-functions/api-create-data.md
Normal file
@ -0,0 +1,52 @@
|
||||
createData()
|
||||
|
||||
creates a data object
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
createData
|
||||
|
||||
object
|
||||
|
||||
parent
|
||||
|
||||
string
|
||||
|
||||
createData
|
||||
|
||||
This creates a data object which will hold assigned variables. It uses
|
||||
the following parameters:
|
||||
|
||||
- `parent` is an optional parameter. It is an uplink to the main
|
||||
Smarty object, a another user-created data object or to user-created
|
||||
template object. These objects can be chained. Templates can access
|
||||
variables assigned to any of the objects in it\'s parent chain.
|
||||
|
||||
Data objects are used to create scopes for assigned variables. They can
|
||||
be used to have controll which variables are seen by which templates.
|
||||
|
||||
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
|
||||
// create data object with its private variable scope
|
||||
$data = $smarty->createData();
|
||||
|
||||
// assign variable to data scope
|
||||
$data->assign('foo','bar');
|
||||
|
||||
// create template object which will use variables from data object
|
||||
$tpl = $smarty->createTemplate('index.tpl',$data);
|
||||
|
||||
// display the template
|
||||
$tpl->display();
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`display()`](#api.display), and
|
||||
[`createTemplate()`](#api.create.template),
|
99
docs/programmers/api-functions/api-create-template.md
Normal file
99
docs/programmers/api-functions/api-create-template.md
Normal file
@ -0,0 +1,99 @@
|
||||
createTemplate()
|
||||
|
||||
returns a template object
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
Smarty\_Internal\_Template
|
||||
|
||||
createTemplate
|
||||
|
||||
string
|
||||
|
||||
template
|
||||
|
||||
object
|
||||
|
||||
parent
|
||||
|
||||
Smarty\_Internal\_Template
|
||||
|
||||
createTemplate
|
||||
|
||||
string
|
||||
|
||||
template
|
||||
|
||||
array
|
||||
|
||||
data
|
||||
|
||||
Smarty\_Internal\_Template
|
||||
|
||||
createTemplate
|
||||
|
||||
string
|
||||
|
||||
template
|
||||
|
||||
string
|
||||
|
||||
cache\_id
|
||||
|
||||
string
|
||||
|
||||
compile\_id
|
||||
|
||||
object
|
||||
|
||||
parent
|
||||
|
||||
Smarty\_Internal\_Template
|
||||
|
||||
createTemplate
|
||||
|
||||
string
|
||||
|
||||
template
|
||||
|
||||
string
|
||||
|
||||
cache\_id
|
||||
|
||||
string
|
||||
|
||||
compile\_id
|
||||
|
||||
array
|
||||
|
||||
data
|
||||
|
||||
This creates a template object which later can be rendered by the
|
||||
[display](#api.display) or [fetch](#api.fetch) method. It uses the
|
||||
following parameters:
|
||||
|
||||
- `template` must be a valid [template resource](#resources) type and
|
||||
path.
|
||||
|
||||
<!-- -->
|
||||
|
||||
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
|
||||
// create template object with its private variable scope
|
||||
$tpl = $smarty->createTemplate('index.tpl');
|
||||
|
||||
// assign variable to template scope
|
||||
$tpl->assign('foo','bar');
|
||||
|
||||
// display the template
|
||||
$tpl->display();
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`display()`](#api.display), and
|
||||
[`templateExists()`](#api.template.exists).
|
15
docs/programmers/api-functions/api-disable-security.md
Normal file
15
docs/programmers/api-functions/api-disable-security.md
Normal file
@ -0,0 +1,15 @@
|
||||
disableSecurity()
|
||||
|
||||
disables template security
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
disableSecurity
|
||||
|
||||
This disables securty checking on templates.
|
||||
|
||||
See also [`enableSecurity()`](#api.enable.security), and
|
||||
[Security](#advanced.features.security).
|
82
docs/programmers/api-functions/api-display.md
Normal file
82
docs/programmers/api-functions/api-display.md
Normal file
@ -0,0 +1,82 @@
|
||||
display()
|
||||
|
||||
displays the template
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
display
|
||||
|
||||
string
|
||||
|
||||
template
|
||||
|
||||
string
|
||||
|
||||
cache\_id
|
||||
|
||||
string
|
||||
|
||||
compile\_id
|
||||
|
||||
This displays the contents of a template. To return the contents of a
|
||||
template into a variable, use [`fetch()`](#api.fetch). Supply a valid
|
||||
[template resource](#resources) type and path. As an optional second
|
||||
parameter, you can pass a `$cache_id`, see the [caching
|
||||
section](#caching) for more information.
|
||||
|
||||
PARAMETER.COMPILEID
|
||||
|
||||
|
||||
<?php
|
||||
include(SMARTY_DIR.'Smarty.class.php');
|
||||
$smarty = new Smarty();
|
||||
$smarty->setCaching(true);
|
||||
|
||||
// only do db calls if cache doesn't exist
|
||||
if(!$smarty->isCached('index.tpl')) {
|
||||
|
||||
// dummy up some data
|
||||
$address = '245 N 50th';
|
||||
$db_data = array(
|
||||
'City' => 'Lincoln',
|
||||
'State' => 'Nebraska',
|
||||
'Zip' => '68502'
|
||||
);
|
||||
|
||||
$smarty->assign('Name', 'Fred');
|
||||
$smarty->assign('Address', $address);
|
||||
$smarty->assign('data', $db_data);
|
||||
|
||||
}
|
||||
|
||||
// display the output
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Use the syntax for [template resources](#resources) to display files
|
||||
outside of the [`$template_dir`](#variable.template.dir) directory.
|
||||
|
||||
|
||||
<?php
|
||||
// absolute filepath
|
||||
$smarty->display('/usr/local/include/templates/header.tpl');
|
||||
|
||||
// absolute filepath (same thing)
|
||||
$smarty->display('file:/usr/local/include/templates/header.tpl');
|
||||
|
||||
// windows absolute filepath (MUST use "file:" prefix)
|
||||
$smarty->display('file:C:/www/pub/templates/header.tpl');
|
||||
|
||||
// include from template resource named "db"
|
||||
$smarty->display('db:header.tpl');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`fetch()`](#api.fetch) and
|
||||
[`templateExists()`](#api.template.exists).
|
41
docs/programmers/api-functions/api-enable-security.md
Normal file
41
docs/programmers/api-functions/api-enable-security.md
Normal file
@ -0,0 +1,41 @@
|
||||
enableSecurity()
|
||||
|
||||
enables template security
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
enableSecurity
|
||||
|
||||
string
|
||||
|
||||
securityclass
|
||||
|
||||
string
|
||||
|
||||
enableSecurity
|
||||
|
||||
object
|
||||
|
||||
securityobject
|
||||
|
||||
string
|
||||
|
||||
enableSecurity
|
||||
|
||||
This enables securty checking on templates. It uses the following
|
||||
parameters:
|
||||
|
||||
- `securityclass` is an optional parameter. It\'s the name of the
|
||||
class with defines the security policy parameters.
|
||||
|
||||
- `securityobject` is an optional parameter. It\'s the object with
|
||||
defines the security policy parameters.
|
||||
|
||||
For the details how to setup a security policy see the
|
||||
[Security](#advanced.features.security) section.
|
||||
|
||||
See also [`disableSecurity()`](#api.disable.security), and
|
||||
[Security](#advanced.features.security).
|
91
docs/programmers/api-functions/api-fetch.md
Normal file
91
docs/programmers/api-functions/api-fetch.md
Normal file
@ -0,0 +1,91 @@
|
||||
fetch()
|
||||
|
||||
returns the template output
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
fetch
|
||||
|
||||
string
|
||||
|
||||
template
|
||||
|
||||
string
|
||||
|
||||
cache\_id
|
||||
|
||||
string
|
||||
|
||||
compile\_id
|
||||
|
||||
This returns the template output instead of [displaying](#api.display)
|
||||
it. Supply a valid [template resource](#resources) type and path. As an
|
||||
optional second parameter, you can pass a `$cache id`, see the [caching
|
||||
section](#caching) for more information.
|
||||
|
||||
PARAMETER.COMPILEID
|
||||
|
||||
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
|
||||
$smarty->setCaching(true);
|
||||
|
||||
// set a separate cache_id for each unique URL
|
||||
$cache_id = md5($_SERVER['REQUEST_URI']);
|
||||
|
||||
// capture the output
|
||||
$output = $smarty->fetch('index.tpl', $cache_id);
|
||||
|
||||
// do something with $output here
|
||||
echo $output;
|
||||
?>
|
||||
|
||||
|
||||
|
||||
The `email_body.tpl` template
|
||||
|
||||
|
||||
Dear {$contact_info.name},
|
||||
|
||||
Welcome and thank you for signing up as a member of our user group.
|
||||
|
||||
Click on the link below to login with your user name
|
||||
of '{$contact_info.username}' so you can post in our forums.
|
||||
|
||||
{$login_url}
|
||||
|
||||
List master
|
||||
|
||||
{textformat wrap=40}
|
||||
This is some long-winded disclaimer text that would automatically get wrapped
|
||||
at 40 characters. This helps make the text easier to read in mail programs that
|
||||
do not wrap sentences for you.
|
||||
{/textformat}
|
||||
|
||||
|
||||
|
||||
The php script using the PHP [`mail()`](&url.php-manual;function.mail)
|
||||
function
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// get $contact_info from db or other resource here
|
||||
|
||||
$smarty->assign('contact_info',$contact_info);
|
||||
$smarty->assign('login_url',"http://{$_SERVER['SERVER_NAME']}/login");
|
||||
|
||||
mail($contact_info['email'], 'Thank You', $smarty->fetch('email_body.tpl'));
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`{fetch}`](#language.function.fetch)
|
||||
[`display()`](#api.display), [`{eval}`](#language.function.eval), and
|
||||
[`templateExists()`](#api.template.exists).
|
23
docs/programmers/api-functions/api-get-cache-dir.md
Normal file
23
docs/programmers/api-functions/api-get-cache-dir.md
Normal file
@ -0,0 +1,23 @@
|
||||
getCacheDir()
|
||||
|
||||
return the directory where the rendered template\'s output is stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
getCacheDir
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// get directory where compiled templates are stored
|
||||
$cacheDir = $smarty->getCacheDir();
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`setCacheDir()`](#api.set.cache.dir) and
|
||||
[`$cache_dir`](#variable.cache.dir).
|
23
docs/programmers/api-functions/api-get-compile-dir.md
Normal file
23
docs/programmers/api-functions/api-get-compile-dir.md
Normal file
@ -0,0 +1,23 @@
|
||||
getCompileDir()
|
||||
|
||||
returns the directory where compiled templates are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
getCompileDir
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// get directory where compiled templates are stored
|
||||
$compileDir = $smarty->getCompileDir();
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`setCompileDir()`](#api.set.compile.dir) and
|
||||
[`$compile_dir`](#variable.compile.dir).
|
40
docs/programmers/api-functions/api-get-config-dir.md
Normal file
40
docs/programmers/api-functions/api-get-config-dir.md
Normal file
@ -0,0 +1,40 @@
|
||||
getConfigDir()
|
||||
|
||||
return the directory where config files are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string\|array
|
||||
|
||||
getConfigDir
|
||||
|
||||
string
|
||||
|
||||
key
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// set some config directories
|
||||
$smarty->setConfigDir(array(
|
||||
'one' => './config',
|
||||
'two' => './config_2',
|
||||
'three' => './config_3',
|
||||
));
|
||||
|
||||
// get all directories where config files are stored
|
||||
$config_dir = $smarty->getConfigDir();
|
||||
var_dump($config_dir); // array
|
||||
|
||||
// get directory identified by key
|
||||
$config_dir = $smarty->getConfigDir('one');
|
||||
var_dump($config_dir); // string
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`setConfigDir()`](#api.set.config.dir),
|
||||
[`addConfigDir()`](#api.add.config.dir) and
|
||||
[`$config_dir`](#variable.config.dir).
|
37
docs/programmers/api-functions/api-get-config-vars.md
Normal file
37
docs/programmers/api-functions/api-get-config-vars.md
Normal file
@ -0,0 +1,37 @@
|
||||
getConfigVars()
|
||||
|
||||
returns the given loaded config variable value
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
array
|
||||
|
||||
getConfigVars
|
||||
|
||||
string
|
||||
|
||||
varname
|
||||
|
||||
If no parameter is given, an array of all loaded [config
|
||||
variables](#language.config.variables) is returned.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// get loaded config template var #foo#
|
||||
$myVar = $smarty->getConfigVars('foo');
|
||||
|
||||
// get all loaded config template vars
|
||||
$all_config_vars = $smarty->getConfigVars();
|
||||
|
||||
// take a look at them
|
||||
print_r($all_config_vars);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`clearConfig()`](#api.clear.config),
|
||||
[`{config_load}`](#language.function.config.load),
|
||||
[`configLoad()`](#api.config.load) and
|
||||
[`getTemplateVars()`](#api.get.template.vars).
|
31
docs/programmers/api-functions/api-get-plugins-dir.md
Normal file
31
docs/programmers/api-functions/api-get-plugins-dir.md
Normal file
@ -0,0 +1,31 @@
|
||||
getPluginsDir()
|
||||
|
||||
return the directory where plugins are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
array
|
||||
|
||||
getPluginsDir
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// set some plugins directories
|
||||
$smarty->setPluginsDir(array(
|
||||
'./plugins',
|
||||
'./plugins_2',
|
||||
));
|
||||
|
||||
// get all directories where plugins are stored
|
||||
$config_dir = $smarty->getPluginsDir();
|
||||
var_dump($config_dir); // array
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`setPluginsDir()`](#api.set.plugins.dir),
|
||||
[`addPluginsDir()`](#api.add.plugins.dir) and
|
||||
[`$plugins_dir`](#variable.plugins.dir).
|
36
docs/programmers/api-functions/api-get-registered-object.md
Normal file
36
docs/programmers/api-functions/api-get-registered-object.md
Normal file
@ -0,0 +1,36 @@
|
||||
getRegisteredObject()
|
||||
|
||||
returns a reference to a registered object
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
array
|
||||
|
||||
getRegisteredObject
|
||||
|
||||
string
|
||||
|
||||
object\_name
|
||||
|
||||
This is useful from within a custom function when you need direct access
|
||||
to a [registered object](#api.register.object). See the
|
||||
[objects](#advanced.features.objects) page for more info.
|
||||
|
||||
|
||||
<?php
|
||||
function smarty_block_foo($params, $smarty)
|
||||
{
|
||||
if (isset($params['object'])) {
|
||||
// get reference to registered object
|
||||
$obj_ref = $smarty->getRegisteredObject($params['object']);
|
||||
// use $obj_ref is now a reference to the object
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`registerObject()`](#api.register.object),
|
||||
[`unregisterObject()`](#api.unregister.object) and [objects
|
||||
page](#advanced.features.objects)
|
40
docs/programmers/api-functions/api-get-tags.md
Normal file
40
docs/programmers/api-functions/api-get-tags.md
Normal file
@ -0,0 +1,40 @@
|
||||
getTags()
|
||||
|
||||
return tags used by template
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
getTags
|
||||
|
||||
object
|
||||
|
||||
template
|
||||
|
||||
This function returns an array of tagname/attribute pairs for all tags
|
||||
used by the template. It uses the following parameters:
|
||||
|
||||
- `template` is the template object.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> This function is experimental.
|
||||
|
||||
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
$smarty = new Smarty;
|
||||
|
||||
// create template object
|
||||
$tpl = $smarty->createTemplate('index.tpl');
|
||||
|
||||
// get tags
|
||||
$tags = $smarty->getTags($tpl);
|
||||
|
||||
print_r($tags);
|
||||
|
||||
?>
|
||||
|
||||
|
40
docs/programmers/api-functions/api-get-template-dir.md
Normal file
40
docs/programmers/api-functions/api-get-template-dir.md
Normal file
@ -0,0 +1,40 @@
|
||||
getTemplateDir()
|
||||
|
||||
return the directory where templates are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string\|array
|
||||
|
||||
getTemplateDir
|
||||
|
||||
string
|
||||
|
||||
key
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// set some template directories
|
||||
$smarty->setTemplateDir(array(
|
||||
'one' => './templates',
|
||||
'two' => './templates_2',
|
||||
'three' => './templates_3',
|
||||
));
|
||||
|
||||
// get all directories where templates are stored
|
||||
$template_dir = $smarty->getTemplateDir();
|
||||
var_dump($template_dir); // array
|
||||
|
||||
// get directory identified by key
|
||||
$template_dir = $smarty->getTemplateDir('one');
|
||||
var_dump($template_dir); // string
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`setTemplateDir()`](#api.set.template.dir),
|
||||
[`addTemplateDir()`](#api.add.template.dir) and
|
||||
[`$template_dir`](#variable.template.dir).
|
37
docs/programmers/api-functions/api-get-template-vars.md
Normal file
37
docs/programmers/api-functions/api-get-template-vars.md
Normal file
@ -0,0 +1,37 @@
|
||||
getTemplateVars()
|
||||
|
||||
returns assigned variable value(s)
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
array
|
||||
|
||||
getTemplateVars
|
||||
|
||||
string
|
||||
|
||||
varname
|
||||
|
||||
If no parameter is given, an array of all [assigned](#api.assign)
|
||||
variables are returned.
|
||||
|
||||
|
||||
<?php
|
||||
// get assigned template var 'foo'
|
||||
$myVar = $smarty->getTemplateVars('foo');
|
||||
|
||||
// get all assigned template vars
|
||||
$all_tpl_vars = $smarty->getTemplateVars();
|
||||
|
||||
// take a look at them
|
||||
print_r($all_tpl_vars);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`assign()`](#api.assign),
|
||||
[`{assign}`](#language.function.assign), [`append()`](#api.append),
|
||||
[`clearAssign()`](#api.clear.assign),
|
||||
[`clearAllAssign()`](#api.clear.all.assign) and
|
||||
[`getConfigVars()`](#api.get.config.vars)
|
81
docs/programmers/api-functions/api-is-cached.md
Normal file
81
docs/programmers/api-functions/api-is-cached.md
Normal file
@ -0,0 +1,81 @@
|
||||
isCached()
|
||||
|
||||
returns true if there is a valid cache for this template
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
bool
|
||||
|
||||
isCached
|
||||
|
||||
string
|
||||
|
||||
template
|
||||
|
||||
string
|
||||
|
||||
cache\_id
|
||||
|
||||
string
|
||||
|
||||
compile\_id
|
||||
|
||||
- This only works if [`$caching`](#variable.caching) is set to one of
|
||||
`Smarty::CACHING_LIFETIME_CURRENT` or
|
||||
`Smarty::CACHING_LIFETIME_SAVED` to enable caching. See the [caching
|
||||
section](#caching) for more info.
|
||||
|
||||
- You can also pass a `$cache_id` as an optional second parameter in
|
||||
case you want [multiple caches](#caching.multiple.caches) for the
|
||||
given template.
|
||||
|
||||
- You can supply a [`$compile id`](#variable.compile.id) as an
|
||||
optional third parameter. If you omit that parameter the persistent
|
||||
[`$compile_id`](#variable.compile.id) is used if its set.
|
||||
|
||||
- If you do not want to pass a `$cache_id` but want to pass a
|
||||
[`$compile_id`](#variable.compile.id) you have to pass NULL as a
|
||||
`$cache_id`.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> If `isCached()` returns TRUE it actually loads the cached output and
|
||||
> stores it internally. Any subsequent call to
|
||||
> [`display()`](#api.display) or [`fetch()`](#api.fetch) will return
|
||||
> this internally stored output and does not try to reload the cache
|
||||
> file. This prevents a race condition that may occur when a second
|
||||
> process clears the cache between the calls to `isCached()` and to
|
||||
> [`display()`](#api.display) in the example above. This also means
|
||||
> calls to [`clearCache()`](#api.clear.cache) and other changes of the
|
||||
> cache-settings may have no effect after `isCached()` returned TRUE.
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
|
||||
|
||||
if(!$smarty->isCached('index.tpl')) {
|
||||
// do database calls, assign vars here
|
||||
}
|
||||
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
|
||||
|
||||
if(!$smarty->isCached('index.tpl', 'FrontPage')) {
|
||||
// do database calls, assign vars here
|
||||
}
|
||||
|
||||
$smarty->display('index.tpl', 'FrontPage');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`clearCache()`](#api.clear.cache),
|
||||
[`clearAllCache()`](#api.clear.all.cache), and [caching
|
||||
section](#caching).
|
42
docs/programmers/api-functions/api-load-filter.md
Normal file
42
docs/programmers/api-functions/api-load-filter.md
Normal file
@ -0,0 +1,42 @@
|
||||
loadFilter()
|
||||
|
||||
load a filter plugin
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
loadFilter
|
||||
|
||||
string
|
||||
|
||||
type
|
||||
|
||||
string
|
||||
|
||||
name
|
||||
|
||||
The first argument specifies the type of the filter to load and can be
|
||||
one of the following: `pre`, `post` or `output`. The second argument
|
||||
specifies the `name` of the filter plugin.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// load prefilter named 'trim'
|
||||
$smarty->loadFilter('pre', 'trim');
|
||||
|
||||
// load another prefilter named 'datefooter'
|
||||
$smarty->loadFilter('pre', 'datefooter');
|
||||
|
||||
// load output filter named 'compress'
|
||||
$smarty->loadFilter('output', 'compress');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`registerFilter()`](#api.register.filter),
|
||||
[`$autoload_filters`](#variable.autoload.filters) and [advanced
|
||||
features](#advanced.features).
|
21
docs/programmers/api-functions/api-mute-expected-errors.md
Normal file
21
docs/programmers/api-functions/api-mute-expected-errors.md
Normal file
@ -0,0 +1,21 @@
|
||||
Smarty::muteExpectedErrors()
|
||||
|
||||
mutes expected warnings and notices deliberately generated by Smarty
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
string
|
||||
|
||||
muteExpectedErrors
|
||||
|
||||
muteExpectedErrors() registers a custom error handler using
|
||||
[set\_error\_handler()](&url.php-manual;set_error_handler). The error
|
||||
handler merely inspects `$errno` and `$errfile` to determine if the
|
||||
given error was produced deliberately and must be ignored, or should be
|
||||
passed on to the next error handler.
|
||||
|
||||
`Smarty::unmuteExpectedErrors()` removes the current error handler.
|
||||
Please note, that if you\'ve registerd any custom error handlers after
|
||||
the muteExpectedErrors() call, the unmute will not remove Smarty\'s
|
||||
muting error handler, but the one registered last.
|
40
docs/programmers/api-functions/api-register-cacheresource.md
Normal file
40
docs/programmers/api-functions/api-register-cacheresource.md
Normal file
@ -0,0 +1,40 @@
|
||||
registerCacheResource()
|
||||
|
||||
dynamically register CacheResources
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
registerCacheResource
|
||||
|
||||
string
|
||||
|
||||
name
|
||||
|
||||
Smarty\_CacheResource
|
||||
|
||||
resource\_handler
|
||||
|
||||
Use this to dynamically register a [CacheResource
|
||||
plugin](#caching.custom) with Smarty. Pass in the `name` of the
|
||||
CacheResource and the object extending Smarty\_CacheResource. See
|
||||
[Custom Cache Implementation](#caching.custom) for more information on
|
||||
how to create custom CacheResources.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> In Smarty2 this used to be a callback function called
|
||||
> `$cache_handler_func`. Smarty3 replaced this callback by the
|
||||
> `Smarty_CacheResource` module.
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->registerCacheResource('mysql', new Smarty_CacheResource_Mysql());
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`unregisterCacheResource()`](#api.unregister.cacheresource)
|
||||
and the [Custom CacheResource Implementation](#caching.custom) section.
|
65
docs/programmers/api-functions/api-register-class.md
Normal file
65
docs/programmers/api-functions/api-register-class.md
Normal file
@ -0,0 +1,65 @@
|
||||
registerClass()
|
||||
|
||||
register a class for use in the templates
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
registerClass
|
||||
|
||||
string
|
||||
|
||||
class\_name
|
||||
|
||||
string
|
||||
|
||||
class\_impl
|
||||
|
||||
Smarty allows you to access static classes from templates as long as the
|
||||
[Security Policy](#advanced.features.security) does not tell it
|
||||
otherwise. If security is enabled, classes registered with
|
||||
`registerClass()` are accessible to templates.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
class Bar {
|
||||
$property = "hello world";
|
||||
}
|
||||
|
||||
$smarty = new Smarty();
|
||||
$smarty->registerClass("Foo", "Bar");
|
||||
|
||||
|
||||
|
||||
|
||||
{* Smarty will access this class as long as it's not prohibited by security *}
|
||||
{Bar::$property}
|
||||
{* Foo translates to the real class Bar *}
|
||||
{Foo::$property}
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
namespace my\php\application {
|
||||
class Bar {
|
||||
$property = "hello world";
|
||||
}
|
||||
}
|
||||
|
||||
$smarty = new Smarty();
|
||||
$smarty->registerClass("Foo", "\my\php\application\Bar");
|
||||
|
||||
|
||||
|
||||
|
||||
{* Foo translates to the real class \my\php\application\Bar *}
|
||||
{Foo::$property}
|
||||
|
||||
|
||||
|
||||
See also [`registerObject()`](#api.register.object), and
|
||||
[Security](#advanced.features.security).
|
@ -0,0 +1,93 @@
|
||||
registerDefaultPluginHandler()
|
||||
|
||||
register a function which gets called on undefined tags
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
registerDefaultPluginHandler
|
||||
|
||||
mixed
|
||||
|
||||
callback
|
||||
|
||||
Register a default plugin handler which gets called if the compiler can
|
||||
not find a definition for a tag otherwise. It uses the following
|
||||
parameters:
|
||||
|
||||
If during compilation Smarty encounters tag which is not defined
|
||||
internal, registered or loacted in the plugins folder it tries to
|
||||
resolve it by calling the registered default plugin handler. The handler
|
||||
may be called several times for same undefined tag looping over valid
|
||||
plugin types.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty = new Smarty();
|
||||
$smarty->registerDefaultPluginHandler('my_plugin_handler');
|
||||
|
||||
/**
|
||||
* Default Plugin Handler
|
||||
*
|
||||
* called when Smarty encounters an undefined tag during compilation
|
||||
*
|
||||
* @param string $name name of the undefined tag
|
||||
* @param string $type tag type (e.g. Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK,
|
||||
Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_MODIFIER, Smarty::PLUGIN_MODIFIERCOMPILER)
|
||||
* @param Smarty_Internal_Template $template template object
|
||||
* @param string &$callback returned function name
|
||||
* @param string &$script optional returned script filepath if function is external
|
||||
* @param bool &$cacheable true by default, set to false if plugin is not cachable (Smarty >= 3.1.8)
|
||||
* @return bool true if successfull
|
||||
*/
|
||||
function my_plugin_handler ($name, $type, $template, &$callback, &$script, &$cacheable)
|
||||
{
|
||||
switch ($type) {
|
||||
case Smarty::PLUGIN_FUNCTION:
|
||||
switch ($name) {
|
||||
case 'scriptfunction':
|
||||
$script = './scripts/script_function_tag.php';
|
||||
$callback = 'default_script_function_tag';
|
||||
return true;
|
||||
case 'localfunction':
|
||||
$callback = 'default_local_function_tag';
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
case Smarty::PLUGIN_COMPILER:
|
||||
switch ($name) {
|
||||
case 'scriptcompilerfunction':
|
||||
$script = './scripts/script_compiler_function_tag.php';
|
||||
$callback = 'default_script_compiler_function_tag';
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
case Smarty::PLUGIN_BLOCK:
|
||||
switch ($name) {
|
||||
case 'scriptblock':
|
||||
$script = './scripts/script_block_tag.php';
|
||||
$callback = 'default_script_block_tag';
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> The return callback must be static; a function name or an array of
|
||||
> class and method name.
|
||||
>
|
||||
> Dynamic callbacks like objects methods are not supported.
|
45
docs/programmers/api-functions/api-register-filter.md
Normal file
45
docs/programmers/api-functions/api-register-filter.md
Normal file
@ -0,0 +1,45 @@
|
||||
registerFilter()
|
||||
|
||||
dynamically register filters
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
registerFilter
|
||||
|
||||
string
|
||||
|
||||
type
|
||||
|
||||
mixed
|
||||
|
||||
callback
|
||||
|
||||
Use this to dynamically register filters to operate on a templates. It
|
||||
uses the following parameters:
|
||||
|
||||
NOTE.PARAMETER.FUNCTION
|
||||
|
||||
A [prefilter](#plugins.prefilters.postfilters) runs through the template
|
||||
source before it gets compiled. See [template
|
||||
prefilters](#advanced.features.prefilters) for more information on how
|
||||
to setup a prefiltering function.
|
||||
|
||||
A [postfilter](#plugins.prefilters.postfilters) runs through the
|
||||
template code after it was compiled to PHP. See [template
|
||||
postfilters](#advanced.features.postfilters) for more information on how
|
||||
to setup a postfiltering function.
|
||||
|
||||
A [outputfilter](#plugins.outputfilters) operates on a template\'s
|
||||
output before it is [displayed](#api.display). See [template output
|
||||
filters](#advanced.features.outputfilters) for more information on how
|
||||
to set up an output filter function.
|
||||
|
||||
See also [`unregisterFilter()`](#api.unregister.filter),
|
||||
[`loadFilter()`](#api.load.filter),
|
||||
[`$autoload_filters`](#variable.autoload.filters), [template pre
|
||||
filters](#advanced.features.prefilters) [template post
|
||||
filters](#advanced.features.postfilters) [template output
|
||||
filters](#advanced.features.outputfilters) section.
|
44
docs/programmers/api-functions/api-register-object.md
Normal file
44
docs/programmers/api-functions/api-register-object.md
Normal file
@ -0,0 +1,44 @@
|
||||
registerObject()
|
||||
|
||||
register an object for use in the templates
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
registerObject
|
||||
|
||||
string
|
||||
|
||||
object\_name
|
||||
|
||||
object
|
||||
|
||||
object
|
||||
|
||||
array
|
||||
|
||||
allowed\_methods\_properties
|
||||
|
||||
boolean
|
||||
|
||||
format
|
||||
|
||||
array
|
||||
|
||||
block\_methods
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> When you register/assign objects to templates, be sure that all
|
||||
> properties and methods accessed from the template are for presentation
|
||||
> purposes only. It is very easy to inject application logic through
|
||||
> objects, and this leads to poor designs that are difficult to manage.
|
||||
> See the Best Practices section of the Smarty website.
|
||||
|
||||
See the [objects section](#advanced.features.objects) for more
|
||||
information.
|
||||
|
||||
See also [`getRegisteredObject()`](#api.get.registered.object), and
|
||||
[`unregisterObject()`](#api.unregister.object).
|
110
docs/programmers/api-functions/api-register-plugin.md
Normal file
110
docs/programmers/api-functions/api-register-plugin.md
Normal file
@ -0,0 +1,110 @@
|
||||
registerPlugin()
|
||||
|
||||
dynamically register plugins
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
registerPlugin
|
||||
|
||||
string
|
||||
|
||||
type
|
||||
|
||||
string
|
||||
|
||||
name
|
||||
|
||||
mixed
|
||||
|
||||
callback
|
||||
|
||||
bool
|
||||
|
||||
cacheable
|
||||
|
||||
mixed
|
||||
|
||||
cache\_attrs
|
||||
|
||||
This method registers functions or methods defined in your script as
|
||||
plugin. It uses the following parameters:
|
||||
|
||||
- `cacheable` and `cache_attrs` can be omitted in most cases. See
|
||||
[controlling cacheability of plugins output](#caching.cacheable) on
|
||||
how to use them properly.
|
||||
|
||||
<!-- -->
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->registerPlugin("function","date_now", "print_current_date");
|
||||
|
||||
function print_current_date($params, $smarty)
|
||||
{
|
||||
if(empty($params["format"])) {
|
||||
$format = "%b %e, %Y";
|
||||
} else {
|
||||
$format = $params["format"];
|
||||
}
|
||||
return strftime($format,time());
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
And in the template
|
||||
|
||||
|
||||
{date_now}
|
||||
|
||||
{* or to format differently *}
|
||||
{date_now format="%Y/%m/%d"}
|
||||
|
||||
|
||||
<?php
|
||||
// function declaration
|
||||
function do_translation ($params, $content, $smarty, &$repeat, $template)
|
||||
{
|
||||
if (isset($content)) {
|
||||
$lang = $params["lang"];
|
||||
// do some translation with $content
|
||||
return $translation;
|
||||
}
|
||||
}
|
||||
|
||||
// register with smarty
|
||||
$smarty->registerPlugin("block","translate", "do_translation");
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Where the template is:
|
||||
|
||||
|
||||
{translate lang="br"}Hello, world!{/translate}
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// let's map PHP's stripslashes function to a Smarty modifier.
|
||||
$smarty->registerPlugin("modifier","ss", "stripslashes");
|
||||
|
||||
?>
|
||||
|
||||
In the template, use `ss` to strip slashes.
|
||||
|
||||
|
||||
<?php
|
||||
{$var|ss}
|
||||
?>
|
||||
|
||||
See also [`unregisterPlugin()`](#api.unregister.plugin), [plugin
|
||||
functions](#plugins.functions), [plugin block
|
||||
functions](#plugins.block.functions), [plugin compiler
|
||||
functions](#plugins.compiler.functions), and the [creating plugin
|
||||
modifiers](#plugins.modifiers) section.
|
46
docs/programmers/api-functions/api-register-resource.md
Normal file
46
docs/programmers/api-functions/api-register-resource.md
Normal file
@ -0,0 +1,46 @@
|
||||
registerResource()
|
||||
|
||||
dynamically register resources
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
registerResource
|
||||
|
||||
string
|
||||
|
||||
name
|
||||
|
||||
Smarty\_resource
|
||||
|
||||
resource\_handler
|
||||
|
||||
Use this to dynamically register a [Resource plugin](#resources) with
|
||||
Smarty. Pass in the `name` of the Resource and the object extending
|
||||
Smarty\_Resource. See [template resources](#resources) for more
|
||||
information on how to setup a function for fetching templates.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> A resource name must be at least two characters in length. One
|
||||
> character resource names will be ignored and used as part of the file
|
||||
> path, such as `$smarty->display('c:/path/to/index.tpl');`
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Prior to Smarty 3.1 `registerResource()` accepted an array of callback
|
||||
> functions. While this is still possible for backward compatibility
|
||||
> reasons, it is strongly discouraged as callback functions have been
|
||||
> deprecated as of Smarty 3.1.
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->registerResource('mysql', new Smarty_Resource_Mysql());
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`unregisterResource()`](#api.unregister.resource) and the
|
||||
[template resources](#resources) section.
|
32
docs/programmers/api-functions/api-set-cache-dir.md
Normal file
32
docs/programmers/api-functions/api-set-cache-dir.md
Normal file
@ -0,0 +1,32 @@
|
||||
setCacheDir()
|
||||
|
||||
set the directory where the rendered template\'s output is stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
Smarty
|
||||
|
||||
setCacheDir
|
||||
|
||||
string
|
||||
|
||||
cache\_dir
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// set directory where rendered template's output is stored
|
||||
$smarty->setCacheDir('./cache');
|
||||
|
||||
// chaining of method calls
|
||||
$smarty->setTemplateDir('./templates')
|
||||
->setCompileDir('./templates_c')
|
||||
->setCacheDir('./cache');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`getCacheDir()`](#api.get.cache.dir) and
|
||||
[`$cache_dir`](#variable.cache.dir).
|
32
docs/programmers/api-functions/api-set-compile-dir.md
Normal file
32
docs/programmers/api-functions/api-set-compile-dir.md
Normal file
@ -0,0 +1,32 @@
|
||||
setCompileDir()
|
||||
|
||||
set the directory where compiled templates are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
Smarty
|
||||
|
||||
setCompileDir
|
||||
|
||||
string
|
||||
|
||||
compile\_dir
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// set directory where compiled templates are stored
|
||||
$smarty->setCompileDir('./templates_c');
|
||||
|
||||
// chaining of method calls
|
||||
$smarty->setTemplateDir('./templates')
|
||||
->setCompileDir('./templates_c')
|
||||
->setCacheDir('./cache');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`getCompileDir()`](#api.get.compile.dir) and
|
||||
[`$compile_dir`](#variable.compile.dir).
|
47
docs/programmers/api-functions/api-set-config-dir.md
Normal file
47
docs/programmers/api-functions/api-set-config-dir.md
Normal file
@ -0,0 +1,47 @@
|
||||
setConfigDir()
|
||||
|
||||
set the directories where config files are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
Smarty
|
||||
|
||||
setConfigDir
|
||||
|
||||
string\|array
|
||||
|
||||
config\_dir
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// set a single directory where the config files are stored
|
||||
$smarty->setConfigDir('./config');
|
||||
|
||||
// view the config dir chain
|
||||
var_dump($smarty->getConfigDir());
|
||||
|
||||
// set multiple directoríes where config files are stored
|
||||
$smarty->setConfigDir(array(
|
||||
'one' => './config',
|
||||
'two' => './config_2',
|
||||
'three' => './config_3',
|
||||
));
|
||||
|
||||
// view the config dir chain
|
||||
var_dump($smarty->getConfigDir());
|
||||
|
||||
// chaining of method calls
|
||||
$smarty->setTemplateDir('./templates')
|
||||
->setConfigDir('./config')
|
||||
->setCompileDir('./templates_c')
|
||||
->setCacheDir('./cache');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`getConfigDir()`](#api.get.config.dir),
|
||||
[`addConfigDir()`](#api.add.config.dir) and
|
||||
[`$config_dir`](#variable.config.dir).
|
46
docs/programmers/api-functions/api-set-plugins-dir.md
Normal file
46
docs/programmers/api-functions/api-set-plugins-dir.md
Normal file
@ -0,0 +1,46 @@
|
||||
setPluginsDir()
|
||||
|
||||
set the directories where plugins are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
Smarty
|
||||
|
||||
setPluginsDir
|
||||
|
||||
string\|array
|
||||
|
||||
plugins\_dir
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// set a single directory where the plugins are stored
|
||||
$smarty->setPluginsDir('./plugins');
|
||||
|
||||
// view the plugins dir chain
|
||||
var_dump($smarty->getPluginsDir());
|
||||
|
||||
// set multiple directoríes where plugins are stored
|
||||
$smarty->setPluginsDir(array(
|
||||
'./plugins',
|
||||
'./plugins_2',
|
||||
));
|
||||
|
||||
// view the plugins dir chain
|
||||
var_dump($smarty->getPluginsDir());
|
||||
|
||||
// chaining of method calls
|
||||
$smarty->setTemplateDir('./templates')
|
||||
->setPluginsDir('./plugins')
|
||||
->setCompileDir('./templates_c')
|
||||
->setCacheDir('./cache');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`getPluginsDir()`](#api.get.plugins.dir),
|
||||
[`addPluginsDir()`](#api.add.plugins.dir) and
|
||||
[`$plugins_dir`](#variable.plugins.dir).
|
46
docs/programmers/api-functions/api-set-template-dir.md
Normal file
46
docs/programmers/api-functions/api-set-template-dir.md
Normal file
@ -0,0 +1,46 @@
|
||||
setTemplateDir()
|
||||
|
||||
set the directories where templates are stored
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
Smarty
|
||||
|
||||
setTemplateDir
|
||||
|
||||
string\|array
|
||||
|
||||
template\_dir
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// set a single directory where the templates are stored
|
||||
$smarty->setTemplateDir('./cache');
|
||||
|
||||
// view the template dir chain
|
||||
var_dump($smarty->getTemplateDir());
|
||||
|
||||
// set multiple directoríes where templates are stored
|
||||
$smarty->setTemplateDir(array(
|
||||
'one' => './templates',
|
||||
'two' => './templates_2',
|
||||
'three' => './templates_3',
|
||||
));
|
||||
|
||||
// view the template dir chain
|
||||
var_dump($smarty->getTemplateDir());
|
||||
|
||||
// chaining of method calls
|
||||
$smarty->setTemplateDir('./templates')
|
||||
->setCompileDir('./templates_c')
|
||||
->setCacheDir('./cache');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`getTemplateDir()`](#api.get.template.dir),
|
||||
[`addTemplateDir()`](#api.add.template.dir) and
|
||||
[`$template_dir`](#variable.template.dir).
|
59
docs/programmers/api-functions/api-template-exists.md
Normal file
59
docs/programmers/api-functions/api-template-exists.md
Normal file
@ -0,0 +1,59 @@
|
||||
templateExists()
|
||||
|
||||
checks whether the specified template exists
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
bool
|
||||
|
||||
templateExists
|
||||
|
||||
string
|
||||
|
||||
template
|
||||
|
||||
It can accept either a path to the template on the filesystem or a
|
||||
resource string specifying the template.
|
||||
|
||||
This example uses `$_GET['page']` to
|
||||
[`{include}`](#language.function.include) a content template. If the
|
||||
template does not exist then an error page is displayed instead. First
|
||||
the `page_container.tpl`
|
||||
|
||||
|
||||
<html>
|
||||
<head><title>{$title}</title></head>
|
||||
<body>
|
||||
{include file='page_top.tpl'}
|
||||
|
||||
{* include middle content page *}
|
||||
{include file=$content_template}
|
||||
|
||||
{include file='page_footer.tpl'}
|
||||
</body>
|
||||
|
||||
|
||||
|
||||
And the php script
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// set the filename eg index.inc.tpl
|
||||
$mid_template = $_GET['page'].'.inc.tpl';
|
||||
|
||||
if( !$smarty->templateExists($mid_template) ){
|
||||
$mid_template = 'page_not_found.tpl';
|
||||
}
|
||||
$smarty->assign('content_template', $mid_template);
|
||||
|
||||
$smarty->display('page_container.tpl');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`display()`](#api.display), [`fetch()`](#api.fetch),
|
||||
[`{include}`](#language.function.include) and
|
||||
[`{insert}`](#language.function.insert)
|
22
docs/programmers/api-functions/api-test-install.md
Normal file
22
docs/programmers/api-functions/api-test-install.md
Normal file
@ -0,0 +1,22 @@
|
||||
testInstall()
|
||||
|
||||
checks Smarty installation
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
testInstall
|
||||
|
||||
This function verifies that all required working folders of the Smarty
|
||||
installation can be accessed. It does output a corresponding protocoll.
|
||||
|
||||
|
||||
<?php
|
||||
require_once('Smarty.class.php');
|
||||
$smarty = new Smarty();
|
||||
$smarty->testInstall();
|
||||
?>
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
unregisterCacheResource()
|
||||
|
||||
dynamically unregister a CacheResource plugin
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
unregisterCacheResource
|
||||
|
||||
string
|
||||
|
||||
name
|
||||
|
||||
Pass in the `name` of the CacheResource.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->unregisterCacheResource('mysql');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`registerCacheResource()`](#api.register.cacheresource) and
|
||||
the [Custom CacheResource Implementation](#caching.custom) section.
|
23
docs/programmers/api-functions/api-unregister-filter.md
Normal file
23
docs/programmers/api-functions/api-unregister-filter.md
Normal file
@ -0,0 +1,23 @@
|
||||
unregisterFilter()
|
||||
|
||||
dynamically unregister a filter
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
unregisterFilter
|
||||
|
||||
string
|
||||
|
||||
type
|
||||
|
||||
string\|array
|
||||
|
||||
callback
|
||||
|
||||
Use this to dynamically unregister filters. It uses the following
|
||||
parameters:
|
||||
|
||||
See also [`registerFilter()`](#api.register.filter).
|
17
docs/programmers/api-functions/api-unregister-object.md
Normal file
17
docs/programmers/api-functions/api-unregister-object.md
Normal file
@ -0,0 +1,17 @@
|
||||
unregisterObject()
|
||||
|
||||
dynamically unregister an object
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
unregisterObject
|
||||
|
||||
string
|
||||
|
||||
object\_name
|
||||
|
||||
See also [`registerObject()`](#api.register.object) and [objects
|
||||
section](#advanced.features.objects)
|
36
docs/programmers/api-functions/api-unregister-plugin.md
Normal file
36
docs/programmers/api-functions/api-unregister-plugin.md
Normal file
@ -0,0 +1,36 @@
|
||||
unregisterPlugin
|
||||
|
||||
dynamically unregister plugins
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
unregisterPlugin
|
||||
|
||||
string
|
||||
|
||||
type
|
||||
|
||||
string
|
||||
|
||||
name
|
||||
|
||||
This method unregisters plugins which previously have been registered by
|
||||
[registerPlugin()](#api.register.plugin), It uses the following
|
||||
parameters:
|
||||
|
||||
<!-- -->
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
// we don't want template designers to have access to function plugin "date_now"
|
||||
$smarty->unregisterPlugin("function","date_now");
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`registerPlugin()`](#api.register.plugin).
|
28
docs/programmers/api-functions/api-unregister-resource.md
Normal file
28
docs/programmers/api-functions/api-unregister-resource.md
Normal file
@ -0,0 +1,28 @@
|
||||
unregisterResource()
|
||||
|
||||
dynamically unregister a resource plugin
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
void
|
||||
|
||||
unregisterResource
|
||||
|
||||
string
|
||||
|
||||
name
|
||||
|
||||
Pass in the `name` of the resource.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->unregisterResource('db');
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`registerResource()`](#api.register.resource) and [template
|
||||
resources](#resources)
|
Reference in New Issue
Block a user