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:
14
docs/programmers/advanced-features.md
Normal file
14
docs/programmers/advanced-features.md
Normal file
@ -0,0 +1,14 @@
|
||||
Advanced Features {#advanced.features}
|
||||
=================
|
||||
|
||||
## Table of contents
|
||||
|
||||
- [Security](./advanced-features/advanced-features-security.md)
|
||||
- [Changing settings by template](./advanced-features/advanced-features-template-settings.md)
|
||||
- [Template Inheritance](./advanced-features/advanced-features-template-inheritance.md)
|
||||
- [Streams](./advanced-features/advanced-features-streams.md)
|
||||
- [Objects](./advanced-features/advanced-features-objects.md)
|
||||
- [Static Classes](./advanced-features/advanced-features-static-classes.md)
|
||||
- [Prefilters](./advanced-features/advanced-features-prefilters.md)
|
||||
- [Postfilters](./advanced-features/advanced-features-postfilters.md)
|
||||
- [Output Filters](./advanced-features/advanced-features-outputfilters.md)
|
@ -0,0 +1,99 @@
|
||||
Objects {#advanced.features.objects}
|
||||
=======
|
||||
|
||||
Smarty allows access to PHP [objects](&url.php-manual;object) through
|
||||
the templates.
|
||||
|
||||
> **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.
|
||||
|
||||
There are two ways to access them.
|
||||
|
||||
- One way is to [register objects](#api.register.object) to the
|
||||
template, then use access them via syntax similar to [custom
|
||||
functions](#language.custom.functions).
|
||||
|
||||
- The other way is to [`assign()`](#api.assign) objects to the
|
||||
templates and access them much like any other assigned variable.
|
||||
|
||||
The first method has a much nicer template syntax. It is also more
|
||||
secure, as a registered object can be restricted to certain methods or
|
||||
properties. However, **a registered object cannot be looped over or
|
||||
assigned in arrays of objects**, etc. The method you choose will be
|
||||
determined by your needs, but use the first method whenever possible to
|
||||
keep template syntax to a minimum.
|
||||
|
||||
If security is enabled, no private methods or functions can be accessed
|
||||
(beginningwith \'\_\'). If a method and property of the same name exist,
|
||||
the method will be used.
|
||||
|
||||
You can restrict the methods and properties that can be accessed by
|
||||
listing them in an array as the third registration parameter.
|
||||
|
||||
By default, parameters passed to objects through the templates are
|
||||
passed the same way [custom functions](#language.custom.functions) get
|
||||
them. An associative array is passed as the first parameter, and the
|
||||
smarty object as the second. If you want the parameters passed one at a
|
||||
time for each argument like traditional object parameter passing, set
|
||||
the fourth registration parameter to FALSE.
|
||||
|
||||
The optional fifth parameter has only effect with `format` being TRUE
|
||||
and contains a list of methods that should be treated as blocks. That
|
||||
means these methods have a closing tag in the template
|
||||
(`{foobar->meth2}...{/foobar->meth2}`) and the parameters to the methods
|
||||
have the same synopsis as the parameters for
|
||||
[`block-function-plugins`](#plugins.block.functions): They get the four
|
||||
parameters `$params`, `$content`, `$smarty` and `&$repeat` and they also
|
||||
behave like block-function-plugins.
|
||||
|
||||
|
||||
<?php
|
||||
// the object
|
||||
|
||||
class My_Object {
|
||||
function meth1($params, $smarty_obj) {
|
||||
return 'this is my meth1';
|
||||
}
|
||||
}
|
||||
|
||||
$myobj = new My_Object;
|
||||
|
||||
// registering the object (will be by reference)
|
||||
$smarty->registerObject('foobar',$myobj);
|
||||
|
||||
// if we want to restrict access to certain methods or properties, list them
|
||||
$smarty->registerObject('foobar',$myobj,array('meth1','meth2','prop1'));
|
||||
|
||||
// if you want to use the traditional object parameter format, pass a boolean of false
|
||||
$smarty->registerObject('foobar',$myobj,null,false);
|
||||
|
||||
// We can also assign objects. assign_by_ref when possible.
|
||||
$smarty->assign_by_ref('myobj', $myobj);
|
||||
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
And here\'s how to access your objects in `index.tpl`:
|
||||
|
||||
|
||||
{* access our registered object *}
|
||||
{foobar->meth1 p1='foo' p2=$bar}
|
||||
|
||||
{* you can also assign the output *}
|
||||
{foobar->meth1 p1='foo' p2=$bar assign='output'}
|
||||
the output was {$output}
|
||||
|
||||
{* access our assigned object *}
|
||||
{$myobj->meth1('foo',$bar)}
|
||||
|
||||
|
||||
|
||||
See also [`registerObject()`](#api.register.object) and
|
||||
[`assign()`](#api.assign).
|
@ -0,0 +1,43 @@
|
||||
Output Filters {#advanced.features.outputfilters}
|
||||
==============
|
||||
|
||||
When the template is invoked via [`display()`](#api.display) or
|
||||
[`fetch()`](#api.fetch), its output can be sent through one or more
|
||||
output filters. This differs from
|
||||
[`postfilters`](#advanced.features.postfilters) because postfilters
|
||||
operate on compiled templates before they are saved to the disk, whereas
|
||||
output filters operate on the template output when it is executed.
|
||||
|
||||
Output filters can be either [registered](#api.register.filter) or
|
||||
loaded from the [plugins directory](#variable.plugins.dir) by using the
|
||||
[`loadFilter()`](#api.load.filter) method or by setting the
|
||||
[`$autoload_filters`](#variable.autoload.filters) variable. Smarty will
|
||||
pass the template output as the first argument, and expect the function
|
||||
to return the result of the processing.
|
||||
|
||||
|
||||
<?php
|
||||
// put this in your application
|
||||
function protect_email($tpl_output, Smarty_Internal_Template $template)
|
||||
{
|
||||
$tpl_output =
|
||||
preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
|
||||
'$1%40$2', $tpl_output);
|
||||
return $tpl_output;
|
||||
}
|
||||
|
||||
// register the outputfilter
|
||||
$smarty->registerFilter("output","protect_email");
|
||||
$smarty->display("index.tpl');
|
||||
|
||||
// now any occurrence of an email address in the template output will have
|
||||
// a simple protection against spambots
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`registerFilter()`](#api.register.filter),
|
||||
[`loadFilter()`](#api.load.filter),
|
||||
[`$autoload_filters`](#variable.autoload.filters),
|
||||
[postfilters](#advanced.features.postfilters) and
|
||||
[`$plugins_dir`](#variable.plugins.dir).
|
@ -0,0 +1,40 @@
|
||||
Postfilters {#advanced.features.postfilters}
|
||||
===========
|
||||
|
||||
Template postfilters are PHP functions that your templates are ran
|
||||
through *after they are compiled*. Postfilters can be either
|
||||
[registered](#api.register.filter) or loaded from the [plugins
|
||||
directory](#variable.plugins.dir) by using the
|
||||
[`loadFilter()`](#api.load.filter) function or by setting the
|
||||
[`$autoload_filters`](#variable.autoload.filters) variable. Smarty will
|
||||
pass the compiled template code as the first argument, and expect the
|
||||
function to return the result of the processing.
|
||||
|
||||
|
||||
<?php
|
||||
// put this in your application
|
||||
function add_header_comment($tpl_source, Smarty_Internal_Template $template)
|
||||
{
|
||||
return "<?php echo \"<!-- Created by Smarty! -->\n\"; ?>\n".$tpl_source;
|
||||
}
|
||||
|
||||
// register the postfilter
|
||||
$smarty->registerFilter('post','add_header_comment');
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
The postfilter above will make the compiled Smarty template `index.tpl`
|
||||
look like:
|
||||
|
||||
|
||||
<!-- Created by Smarty! -->
|
||||
{* rest of template content... *}
|
||||
|
||||
|
||||
|
||||
See also [`registerFilter()`](#api.register.filter),
|
||||
[prefilters](#advanced.features.prefilters),
|
||||
[outputfilters](#advanced.features.outputfilters), and
|
||||
[`loadFilter()`](#api.load.filter).
|
@ -0,0 +1,36 @@
|
||||
Prefilters {#advanced.features.prefilters}
|
||||
==========
|
||||
|
||||
Template prefilters are PHP functions that your templates are ran
|
||||
through *before they are compiled*. This is good for preprocessing your
|
||||
templates to remove unwanted comments, keeping an eye on what people are
|
||||
putting in their templates, etc.
|
||||
|
||||
Prefilters can be either [registered](#api.register.filter) or loaded
|
||||
from the [plugins directory](#variable.plugins.dir) by using
|
||||
[`loadFilter()`](#api.load.filter) function or by setting the
|
||||
[`$autoload_filters`](#variable.autoload.filters) variable.
|
||||
|
||||
Smarty will pass the template source code as the first argument, and
|
||||
expect the function to return the resulting template source code.
|
||||
|
||||
This will remove all the html comments in the template source.
|
||||
|
||||
|
||||
<?php
|
||||
// put this in your application
|
||||
function remove_dw_comments($tpl_source, Smarty_Internal_Template $template)
|
||||
{
|
||||
return preg_replace("/<!--#.*-->/U",'',$tpl_source);
|
||||
}
|
||||
|
||||
// register the prefilter
|
||||
$smarty->registerFilter('pre','remove_dw_comments');
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`registerFilter()`](#api.register.filter),
|
||||
[postfilters](#advanced.features.postfilters) and
|
||||
[`loadFilter()`](#api.load.filter).
|
168
docs/programmers/advanced-features/advanced-features-security.md
Normal file
168
docs/programmers/advanced-features/advanced-features-security.md
Normal file
@ -0,0 +1,168 @@
|
||||
Security {#advanced.features.security}
|
||||
========
|
||||
|
||||
Security is good for situations when you have untrusted parties editing
|
||||
the templates eg via ftp, and you want to reduce the risk of system
|
||||
security compromises through the template language.
|
||||
|
||||
The settings of the security policy are defined by properties of an
|
||||
instance of the Smarty\_Security class. These are the possible settings:
|
||||
|
||||
- `$php_handling` determines how Smarty to handle PHP code embedded in
|
||||
templates. Possible values are:
|
||||
|
||||
- Smarty::PHP\_PASSTHRU -\> echo PHP tags as they are
|
||||
|
||||
- Smarty::PHP\_QUOTE -\> escape tags as entities
|
||||
|
||||
- Smarty::PHP\_REMOVE -\> remove php tags
|
||||
|
||||
- Smarty::PHP\_ALLOW -\> execute php tags
|
||||
|
||||
The default value is Smarty::PHP\_PASSTHRU.
|
||||
|
||||
If security is enabled the [`$php_handling`](#variable.php.handling)
|
||||
setting of the Smarty object is not checked for security.
|
||||
|
||||
- `$secure_dir` is an array of template directories that are
|
||||
considered secure. [`$template_dir`](#variable.template.dir)
|
||||
concidered secure implicitly. The default is an empty array.
|
||||
|
||||
- `$trusted_dir` is an array of all directories that are considered
|
||||
trusted. Trusted directories are where you keep php scripts that are
|
||||
executed directly from the templates with
|
||||
[`{include_php}`](#language.function.include.php). The default is an
|
||||
empty array.
|
||||
|
||||
- `$trusted_uri` is an array of regular expressions matching URIs that
|
||||
are considered trusted. This security directive used by
|
||||
[`{fetch}`](#language.function.fetch) and
|
||||
[`{html_image}`](#language.function.html.image). URIs passed to
|
||||
these functions are reduced to `{$PROTOCOL}://{$HOSTNAME}` to allow
|
||||
simple regular expressions (without having to deal with edge cases
|
||||
like authentication-tokens).
|
||||
|
||||
The expression `'#https?://.*smarty.net$#i'` would allow accessing
|
||||
the follwing URIs:
|
||||
|
||||
- `http://smarty.net/foo`
|
||||
|
||||
- `http://smarty.net/foo`
|
||||
|
||||
- `http://www.smarty.net/foo`
|
||||
|
||||
- `http://smarty.net/foo`
|
||||
|
||||
- `https://foo.bar.www.smarty.net/foo/bla?blubb=1`
|
||||
|
||||
but deny access to these URIs:
|
||||
|
||||
- `http://smarty.com/foo` (not matching top-level domain \"com\")
|
||||
|
||||
- `ftp://www.smarty.net/foo` (not matching protocol \"ftp\")
|
||||
|
||||
- `http://www.smarty.net.otherdomain.com/foo` (not matching end of
|
||||
domain \"smarty.net\")
|
||||
|
||||
- `$static_classes` is an array of classes that are considered
|
||||
trusted. The default is an empty array which allows access to all
|
||||
static classes. To disable access to all static classes set
|
||||
\$static\_classes = null.
|
||||
|
||||
- `$php_functions` is an array of PHP functions that are considered
|
||||
trusted and can be used from within template. To disable access to
|
||||
all PHP functions set \$php\_functions = null. An empty array (
|
||||
\$php\_functions = array() ) will allow all PHP functions. The
|
||||
default is array(\'isset\', \'empty\', \'count\', \'sizeof\',
|
||||
\'in\_array\', \'is\_array\',\'time\',\'nl2br\').
|
||||
|
||||
- `$php_modifiers` is an array of PHP functions that are considered
|
||||
trusted and can be used from within template as modifier. To disable
|
||||
access to all PHP modifier set \$php\_modifier = null. An empty
|
||||
array ( \$php\_modifier = array() ) will allow all PHP functions.
|
||||
The default is array(\'escape\',\'count\').
|
||||
|
||||
- `$streams` is an array of streams that are considered trusted and
|
||||
can be used from within template. To disable access to all streams
|
||||
set \$streams = null. An empty array ( \$streams = array() ) will
|
||||
allow all streams. The default is array(\'file\').
|
||||
|
||||
- `$allowed_modifiers` is an array of (registered / autoloaded)
|
||||
modifiers that should be accessible to the template. If this array
|
||||
is non-empty, only the herein listed modifiers may be used. This is
|
||||
a whitelist.
|
||||
|
||||
- `$disabled_modifiers` is an array of (registered / autoloaded)
|
||||
modifiers that may not be accessible to the template.
|
||||
|
||||
- `$allowed_tags` is a boolean flag which controls if constants can
|
||||
function-, block and filter plugins that should be accessible to the
|
||||
template. If this array is non-empty, only the herein listed
|
||||
modifiers may be used. This is a whitelist.
|
||||
|
||||
- `$disabled_tags` is an array of (registered / autoloaded) function-,
|
||||
block and filter plugins that may not be accessible to the template.
|
||||
|
||||
- `$allow_constants` is a boolean flag which controls if constants can
|
||||
be accessed by the template. The default is \"true\".
|
||||
|
||||
- `$allow_super_globals` is a boolean flag which controls if the PHP
|
||||
super globals can be accessed by the template. The default is
|
||||
\"true\".
|
||||
|
||||
- `$allow_php_tag` is a boolean flag which controls if {php} and
|
||||
{include\_php} tags can be used by the template. The default is
|
||||
\"false\".
|
||||
|
||||
If security is enabled, no private methods, functions or properties of
|
||||
static classes or assigned objects can be accessed (beginningwith
|
||||
\'\_\') by the template.
|
||||
|
||||
To customize the security policy settings you can extend the
|
||||
Smarty\_Security class or create an instance of it.
|
||||
|
||||
|
||||
<?php
|
||||
require 'Smarty.class.php';
|
||||
|
||||
class My_Security_Policy extends Smarty_Security {
|
||||
// disable all PHP functions
|
||||
public $php_functions = null;
|
||||
// remove PHP tags
|
||||
public $php_handling = Smarty::PHP_REMOVE;
|
||||
// allow everthing as modifier
|
||||
public $php_modifiers = array();
|
||||
}
|
||||
$smarty = new Smarty();
|
||||
// enable security
|
||||
$smarty->enableSecurity('My_Security_Policy');
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
require 'Smarty.class.php';
|
||||
$smarty = new Smarty();
|
||||
$my_security_policy = new Smarty_Security($smarty);
|
||||
// disable all PHP functions
|
||||
$my_security_policy->php_functions = null;
|
||||
// remove PHP tags
|
||||
$my_security_policy->php_handling = Smarty::PHP_REMOVE;
|
||||
// allow everthing as modifier
|
||||
$my_security_policy->php_modifiers = array();
|
||||
// enable security
|
||||
$smarty->enableSecurity($my_security_policy);
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
require 'Smarty.class.php';
|
||||
$smarty = new Smarty();
|
||||
// enable default security
|
||||
$smarty->enableSecurity();
|
||||
?>
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Most security policy settings are only checked when the template gets
|
||||
> compiled. For that reasion you should delete all cached and compiled
|
||||
> template files when you change your security settings.
|
@ -0,0 +1,27 @@
|
||||
Static Classes {#advanced.features.static.classes}
|
||||
==============
|
||||
|
||||
You can directly access static classes. The syntax is the same as in
|
||||
PHP.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Direct access to PHP classes is not recommended. This ties the
|
||||
> underlying application code structure directly to the presentation,
|
||||
> and also complicates template syntax. It is recommended to register
|
||||
> plugins which insulate templates from PHP classes/objects. Use at your
|
||||
> own discretion. See the Best Practices section of the Smarty website.
|
||||
|
||||
|
||||
{assign var=foo value=myclass::BAR} <--- class constant BAR
|
||||
|
||||
{assign var=foo value=myclass::method()} <--- method result
|
||||
|
||||
{assign var=foo value=myclass::method1()->method2} <--- method chaining
|
||||
|
||||
{assign var=foo value=myclass::$bar} <--- property bar of class myclass
|
||||
|
||||
{assign var=foo value=$bar::method} <--- using Smarty variable bar as class name
|
||||
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
Streams {#advanced.features.streams}
|
||||
=======
|
||||
|
||||
You can also use streams to call variables. *{\$foo:bar}* will use the
|
||||
*foo://bar* stream to get the template variable.
|
||||
|
||||
Using a PHP stream for a template variable resource from within a
|
||||
template.
|
||||
|
||||
|
||||
{$foo:bar}
|
||||
|
||||
|
||||
|
||||
See also [`Template Resources`](#resources)
|
@ -0,0 +1,128 @@
|
||||
Template Inheritance {#advanced.features.template.inheritance}
|
||||
====================
|
||||
|
||||
Inheritance brings the concept of Object Oriented Programming to
|
||||
templates, allowing you to define one (or more) base templates that can
|
||||
be extended by child templates. Extending means that the child template
|
||||
can override all or some of the parent named block areas.
|
||||
|
||||
- The inheritance tree can be as deep as you want, meaning you can
|
||||
extend a file that extends another one that extends another one and
|
||||
so on.
|
||||
|
||||
- The child templates can not define any content besides what\'s
|
||||
inside [`{block}`](#language.function.block) tags they override.
|
||||
Anything outside of [`{block}`](#language.function.block) tags will
|
||||
be removed.
|
||||
|
||||
- The content of [`{block}`](#language.function.block) tags from child
|
||||
and parent templates can be merged by the `append` or `prepend`
|
||||
[`{block}`](#language.function.block) tag option flags and
|
||||
`{$smarty.block.parent}` or `{$smarty.block.child}` placeholders.
|
||||
|
||||
- Template inheritance is a compile time process which creates a
|
||||
single compiled template file. Compared to corresponding solutions
|
||||
based on subtemplates included with the
|
||||
[`{include}`](#language.function.include) tag it does have much
|
||||
better performance when rendering.
|
||||
|
||||
- The child template extends its parent defined with the
|
||||
[`{extends}`](#language.function.extends) tag, which must be the
|
||||
first line in the child template. Instead of using the
|
||||
[`{extends}`](#language.function.extends) tags in the template files
|
||||
you can define the whole template inheritance tree in the PHP script
|
||||
when you are calling [`fetch()`](#api.fetch) or
|
||||
[`display()`](#api.display) with the `extends:` template resource
|
||||
type. The later provides even more flexibillity.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> When `$compile_check` is enabled, all files in the inheritance tree
|
||||
> are checked for modifications upon each invocation. You may want to
|
||||
> disable `$compile_check` on production servers for this reason.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> If you have a subtemplate which is included with
|
||||
> [`{include}`](#language.function.include) and it contains
|
||||
> [`{block}`](#language.function.block) areas it works only if the
|
||||
> [`{include}`](#language.function.include) itself is called from within
|
||||
> a surrounding [`{block}`](#language.function.block). In the final
|
||||
> parent template you may need a dummy
|
||||
> [`{block}`](#language.function.block) for it.
|
||||
|
||||
layout.tpl (parent)
|
||||
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>{block name=title}Default Page Title{/block}</title>
|
||||
{block name=head}{/block}
|
||||
</head>
|
||||
<body>
|
||||
{block name=body}{/block}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
myproject.tpl (child)
|
||||
|
||||
|
||||
{extends file='layout.tpl'}
|
||||
{block name=head}
|
||||
<link href="/css/mypage.css" rel="stylesheet" type="text/css"/>
|
||||
<script src="/js/mypage.js"></script>
|
||||
{/block}
|
||||
|
||||
|
||||
|
||||
|
||||
mypage.tpl (grandchild)
|
||||
|
||||
|
||||
{extends file='myproject.tpl'}
|
||||
{block name=title}My Page Title{/block}
|
||||
{block name=head}
|
||||
<link href="/css/mypage.css" rel="stylesheet" type="text/css"/>
|
||||
<script src="/js/mypage.js"></script>
|
||||
{/block}
|
||||
{block name=body}My HTML Page Body goes here{/block}
|
||||
|
||||
|
||||
|
||||
To render the above use
|
||||
|
||||
|
||||
$smarty->display('mypage.tpl');
|
||||
|
||||
The resulting output is
|
||||
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>My Page Title</title>
|
||||
<link href="/css/mypage.css" rel="stylesheet" type="text/css"/>
|
||||
<script src="/js/mypage.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
My HTML Page Body goes here
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Instead of using [`{extends}`](#language.function.extends) tags in the
|
||||
template files you can define the inheritance tree in your PHP script by
|
||||
using the [`extends:` resource](#resources.extends) type.
|
||||
|
||||
The code below will return same result as the example above.
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->display('extends:layout.tpl|myproject.tpl|mypage.tpl');
|
||||
?>
|
||||
|
||||
|
||||
|
||||
See also [`{block}`](#language.function.block),
|
||||
[`{extends}`](#language.function.extends) and [`extends:`
|
||||
resource](#resources.extends)
|
@ -0,0 +1,32 @@
|
||||
Changing settings by template {#advanced.features.template.settings}
|
||||
=============================
|
||||
|
||||
Normally you configure the Smarty settings by modifying the
|
||||
[`Smarty class variables`](#api.variables). Furthermore you can register
|
||||
plugins, filters etc. with [`Smarty functions`](#api.functions).
|
||||
Modifications done to the Smarty object will be global for all
|
||||
templates.
|
||||
|
||||
However the Smarty class variables and functions can be accessed or
|
||||
called by induvidual template objects. Modification done to a template
|
||||
object will apply only for that template and its included subtemplates.
|
||||
|
||||
|
||||
<?php
|
||||
$tpl = $smarty->createTemplate('index.tpl);
|
||||
$tpl->cache_lifetime = 600;
|
||||
//or
|
||||
$tpl->setCacheLifetime(600);
|
||||
$smarty->display($tpl);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
$tpl = $smarty->createTemplate('index.tpl);
|
||||
$tpl->registerPlugin('modifier','mymodifier');
|
||||
$smarty->display($tpl);
|
||||
?>
|
||||
|
||||
|
64
docs/programmers/api-functions.md
Normal file
64
docs/programmers/api-functions.md
Normal file
@ -0,0 +1,64 @@
|
||||
Smarty Class Methods {#api.functions}
|
||||
====================
|
||||
|
||||
## Table of contents
|
||||
|
||||
- [addConfigDir()](./api-functions/api-add-config-dir.md) — add a directory to the list of directories where config files are stored
|
||||
- [addPluginsDir()](./api-functions/api-add-plugins-dir.md) — add a directory to the list of directories where plugins are stored
|
||||
- [addTemplateDir()](./api-functions/api-add-template-dir.md) — add a directory to the list of directories where templates are stored
|
||||
- [append()](./api-functions/api-append.md) — append an element to an assigned array
|
||||
- [appendByRef()](./api-functions/api-append-by-ref.md) — append values by reference
|
||||
- [assign()](./api-functions/api-assign.md) — assign variables/objects to the templates
|
||||
- [assignByRef()](./api-functions/api-assign-by-ref.md) — assign values by reference
|
||||
- [clearAllAssign()](./api-functions/api-clear-all-assign.md) — clears the values of all assigned variables
|
||||
- [clearAllCache()](./api-functions/api-clear-all-cache.md) — clears the entire template cache
|
||||
- [clearAssign()](./api-functions/api-clear-assign.md) — clears the value of an assigned variable
|
||||
- [clearCache()](./api-functions/api-clear-cache.md) — clears the cache for a specific template
|
||||
- [clearCompiledTemplate()](./api-functions/api-clear-compiled-tpl.md) — clears the compiled version of the specified template resource
|
||||
- [clearConfig()](./api-functions/api-clear-config.md) — clears assigned config variables
|
||||
- [compileAllConfig()](./api-functions/api-compile-all-config.md) — compiles all known config files
|
||||
- [compileAllTemplates()](./api-functions/api-compile-all-templates.md) — compiles all known templates
|
||||
- [configLoad()](./api-functions/api-config-load.md) — loads config file data and assigns it to the template
|
||||
- [createData()](./api-functions/api-create-data.md) — creates a data object
|
||||
- [createTemplate()](./api-functions/api-create-template.md) — returns a template object
|
||||
- [disableSecurity()](./api-functions/api-disable-security.md) — disables template security
|
||||
- [display()](./api-functions/api-display.md) — displays the template
|
||||
- [enableSecurity()](./api-functions/api-enable-security.md) — enables template security
|
||||
- [fetch()](./api-functions/api-fetch.md) — returns the template output
|
||||
- [getCacheDir()](./api-functions/api-get-cache-dir.md) — return the directory where the rendered template's output is stored
|
||||
- [getCompileDir()](./api-functions/api-get-compile-dir.md) — returns the directory where compiled templates are stored
|
||||
- [getConfigDir()](./api-functions/api-get-config-dir.md) — return the directory where config files are stored
|
||||
- [getConfigVars()](./api-functions/api-get-config-vars.md) — returns the given loaded config variable value
|
||||
- [getPluginsDir()](./api-functions/api-get-plugins-dir.md) — return the directory where plugins are stored
|
||||
- [getRegisteredObject()](./api-functions/api-get-registered-object.md) — returns a reference to a registered object
|
||||
- [getTags()](./api-functions/api-get-tags.md) — return tags used by template
|
||||
- [getTemplateDir()](./api-functions/api-get-template-dir.md) — return the directory where templates are stored
|
||||
- [getTemplateVars()](./api-functions/api-get-template-vars.md) — returns assigned variable value(s)
|
||||
- [isCached()](./api-functions/api-is-cached.md) — returns true if there is a valid cache for this template
|
||||
- [loadFilter()](./api-functions/api-load-filter.md) — load a filter plugin
|
||||
- [muteExpectedErrors()](./api-functions/api-mute-expected-errors.md) — mutes expected warnings and notices deliberately generated by Smarty
|
||||
- [registerCacheResource()](./api-functions/api-register-cacheresource.md) — dynamically register CacheResources
|
||||
- [registerClass()](./api-functions/api-register-class.md) — register a class for use in the templates
|
||||
- [registerDefaultPluginHandler()](./api-functions/api-register-default-plugin-handler.md) — register a function which gets called on undefined tags
|
||||
- [registerFilter()](./api-functions/api-register-filter.md) — dynamically register filters
|
||||
- [registerPlugin()](./api-functions/api-register-plugin.md) — dynamically register plugins
|
||||
- [registerObject()](./api-functions/api-register-object.md) — register an object for use in the templates
|
||||
- [registerResource()](./api-functions/api-register-resource.md) — dynamically register resources
|
||||
- [setCacheDir()](./api-functions/api-set-cache-dir.md) — set the directory where the rendered template's output is stored
|
||||
- [setCompileDir()](./api-functions/api-set-compile-dir.md) — set the directory where compiled templates are stored
|
||||
- [setConfigDir()](./api-functions/api-set-config-dir.md) — set the directories where config files are stored
|
||||
- [setPluginsDir()](./api-functions/api-set-plugins-dir.md) — set the directories where plugins are stored
|
||||
- [setTemplateDir()](./api-functions/api-set-template-dir.md) — set the directories where templates are stored
|
||||
- [templateExists()](./api-functions/api-template-exists.md) — checks whether the specified template exists
|
||||
- [unregisterCacheResource()](./api-functions/api-unregister-cacheresource.md) — dynamically unregister a CacheResource plugin
|
||||
- [unregisterFilter()](./api-functions/api-unregister-filter.md) — dynamically unregister a filter
|
||||
- [unregisterPlugin()](./api-functions/api-unregister-plugin.md) — dynamically unregister plugins
|
||||
- [unregisterObject()](./api-functions/api-unregister-object.md) — dynamically unregister an object
|
||||
- [unregisterResource()](./api-functions/api-unregister-resource.md) — dynamically unregister a resource plugin
|
||||
- [testInstall()](./api-functions/api-test-install.md) — checks Smarty installation
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> See
|
||||
> [`Changing settings by template`](./advanced-features/advanced-features-template-settings.md)
|
||||
> section for how to use the functions for individual templates.
|
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)
|
64
docs/programmers/api-variables.md
Normal file
64
docs/programmers/api-variables.md
Normal file
@ -0,0 +1,64 @@
|
||||
Smarty Class Variables {#api.variables}
|
||||
======================
|
||||
|
||||
These are all of the available Smarty class variables. You can access
|
||||
them directly, or use the corresponding setter/getter methods.
|
||||
|
||||
- [$allow_php_templates](./api-variables/variable-allow-php-templates.md)
|
||||
- [$auto_literal](./api-variables/variable-auto-literal.md)
|
||||
- [$autoload_filters](./api-variables/variable-autoload-filters.md)
|
||||
- [$cache_dir](./api-variables/variable-cache-dir.md)
|
||||
- [$cache_id](./api-variables/variable-cache-id.md)
|
||||
- [$cache_lifetime](./api-variables/variable-cache-lifetime.md)
|
||||
- [$cache_locking](./api-variables/variable-cache-locking.md)
|
||||
- [$cache_modified_check](./api-variables/variable-cache-modified-check.md)
|
||||
- [$caching](./api-variables/variable-caching.md)
|
||||
- [$caching_type](./api-variables/variable-caching-type.md)
|
||||
- [$compile_check](./api-variables/variable-compile-check.md)
|
||||
- [$compile_dir](./api-variables/variable-compile-dir.md)
|
||||
- [$compile_id](./api-variables/variable-compile-id.md)
|
||||
- [$compile_locking](./api-variables/variable-compile-locking.md)
|
||||
- [$compiler_class](./api-variables/variable-compiler-class.md)
|
||||
- [$config_booleanize](./api-variables/variable-config-booleanize.md)
|
||||
- [$config_dir](./api-variables/variable-config-dir.md)
|
||||
- [$config_overwrite](./api-variables/variable-config-overwrite.md)
|
||||
- [$config_read_hidden](./api-variables/variable-config-read-hidden.md)
|
||||
- [$debug_tpl](./api-variables/variable-debug-template.md)
|
||||
- [$debugging](./api-variables/variable-debugging.md)
|
||||
- [$debugging_ctrl](./api-variables/variable-debugging-ctrl.md)
|
||||
- [$default_config_type](./api-variables/variable-default-config-type.md)
|
||||
- [$default_modifiers](./api-variables/variable-default-modifiers.md)
|
||||
- [$default_resource_type](./api-variables/variable-default-resource-type.md)
|
||||
- [$default_config_handler_func](./api-variables/variable-default-config-handler-func.md)
|
||||
- [$default_template_handler_func](./api-variables/variable-default-template-handler-func.md)
|
||||
- [$direct_access_security](./api-variables/variable-direct-access-security.md)
|
||||
- [$error_reporting](./api-variables/variable-error-reporting.md)
|
||||
- [$escape_html](./api-variables/variable-escape-html.md)
|
||||
- [$force_cache](./api-variables/variable-force-cache.md)
|
||||
- [$force_compile](./api-variables/variable-force-compile.md)
|
||||
- [$left_delimiter](./api-variables/variable-left-delimiter.md)
|
||||
- [$locking_timeout](./api-variables/variable-locking-timeout.md)
|
||||
- [$merge_compiled_includes](./api-variables/variable-merge-compiled-includes.md)
|
||||
- [$php_handling](./api-variables/variable-php-handling.md)
|
||||
- [$plugins_dir](./api-variables/variable-plugins-dir.md)
|
||||
- [$right_delimiter](./api-variables/variable-right-delimiter.md)
|
||||
- [$smarty_debug_id](./api-variables/variable-smarty-debug-id.md)
|
||||
- [$template_dir](./api-variables/variable-template-dir.md)
|
||||
- [$trusted_dir](./api-variables/variable-trusted-dir.md)
|
||||
- [$use_include_path](./api-variables/variable-use-include-path.md)
|
||||
- [$use_sub_dirs](./api-variables/variable-use-sub-dirs.md)
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> All class variables have magic setter/getter methods available.
|
||||
> setter/getter methods are camelCaseFormat, unlike the variable itself.
|
||||
> So for example, you can set and get the \$smarty-\>template\_dir
|
||||
> variable with \$smarty-\>setTemplateDir(\$dir) and \$dir =
|
||||
> \$smarty-\>getTemplateDir() respectively.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> See
|
||||
> [`Changing settings by template`](./advanced-features/advanced-features-template-settings.md)
|
||||
> section for how to change Smarty class variables for individual
|
||||
> templates.
|
@ -0,0 +1,18 @@
|
||||
\$allow\_php\_templates {#variable.allow.php.templates}
|
||||
=======================
|
||||
|
||||
By default the PHP template file resource is disabled. Setting
|
||||
`$allow_php_templates` to TRUE will enable PHP template files.
|
||||
|
||||
::: {.informalexample}
|
||||
|
||||
<?php
|
||||
$smarty->allow_php_templates = true;
|
||||
?>
|
||||
|
||||
|
||||
:::
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> The PHP template file resource is an undocumented deprecated feature.
|
17
docs/programmers/api-variables/variable-auto-literal.md
Normal file
17
docs/programmers/api-variables/variable-auto-literal.md
Normal file
@ -0,0 +1,17 @@
|
||||
\$auto\_literal {#variable.auto.literal}
|
||||
===============
|
||||
|
||||
The Smarty delimiter tags { and } will be ignored so long as they are
|
||||
surrounded by white space. This behavior can be disabled by setting
|
||||
auto\_literal to false.
|
||||
|
||||
::: {.informalexample}
|
||||
|
||||
<?php
|
||||
$smarty->auto_literal = false;
|
||||
?>
|
||||
|
||||
|
||||
:::
|
||||
|
||||
See also [Escaping Smarty Parsing](#language.escaping),
|
21
docs/programmers/api-variables/variable-autoload-filters.md
Normal file
21
docs/programmers/api-variables/variable-autoload-filters.md
Normal file
@ -0,0 +1,21 @@
|
||||
\$autoload\_filters {#variable.autoload.filters}
|
||||
===================
|
||||
|
||||
If there are some filters that you wish to load on every template
|
||||
invocation, you can specify them using this variable and Smarty will
|
||||
automatically load them for you. The variable is an associative array
|
||||
where keys are filter types and values are arrays of the filter names.
|
||||
For example:
|
||||
|
||||
::: {.informalexample}
|
||||
|
||||
<?php
|
||||
$smarty->autoload_filters = array('pre' => array('trim', 'stamp'),
|
||||
'output' => array('convert'));
|
||||
?>
|
||||
|
||||
|
||||
:::
|
||||
|
||||
See also [`registerFilter()`](#api.register.filter) and
|
||||
[`loadFilter()`](#api.load.filter)
|
35
docs/programmers/api-variables/variable-cache-dir.md
Normal file
35
docs/programmers/api-variables/variable-cache-dir.md
Normal file
@ -0,0 +1,35 @@
|
||||
\$cache\_dir {#variable.cache.dir}
|
||||
============
|
||||
|
||||
This is the name of the directory where template caches are stored. By
|
||||
default this is `./cache`, meaning that Smarty will look for the
|
||||
`cache/` directory in the same directory as the executing php script.
|
||||
**This directory must be writeable by the web server**, [see
|
||||
install](#installing.smarty.basic) for more info.
|
||||
|
||||
You can also use your own [custom cache implementation](#caching.custom)
|
||||
to control cache files, which will ignore this setting. See also
|
||||
[`$use_sub_dirs`](#variable.use.sub.dirs).
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> This setting must be either a relative or absolute path. include\_path
|
||||
> is not used for writing files.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> It is not recommended to put this directory under the web server
|
||||
> document root.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> As of Smarty 3.1 the attribute \$cache\_dir is no longer accessible
|
||||
> directly. Use [`getCacheDir()`](#api.get.cache.dir) and
|
||||
> [`setCacheDir()`](#api.set.cache.dir) instead.
|
||||
|
||||
See also [`getCacheDir()`](#api.get.cache.dir),
|
||||
[`setCacheDir()`](#api.set.cache.dir), [`$caching`](#variable.caching),
|
||||
[`$use_sub_dirs`](#variable.use.sub.dirs),
|
||||
[`$cache_lifetime`](#variable.cache.lifetime),
|
||||
[`$cache_modified_check`](#variable.cache.modified.check) and the
|
||||
[caching section](#caching).
|
11
docs/programmers/api-variables/variable-cache-id.md
Normal file
11
docs/programmers/api-variables/variable-cache-id.md
Normal file
@ -0,0 +1,11 @@
|
||||
\$cache\_id {#variable.cache.id}
|
||||
===========
|
||||
|
||||
Persistent cache\_id identifier. As an alternative to passing the same
|
||||
`$cache_id` to each and every function call, you can set this
|
||||
`$cache_id` and it will be used implicitly thereafter.
|
||||
|
||||
With a `$cache_id` you can have multiple cache files for a single call
|
||||
to [`display()`](#api.display) or [`fetch()`](#api.fetch) depending for
|
||||
example from different content of the same template. See the [caching
|
||||
section](#caching) for more information.
|
30
docs/programmers/api-variables/variable-cache-lifetime.md
Normal file
30
docs/programmers/api-variables/variable-cache-lifetime.md
Normal file
@ -0,0 +1,30 @@
|
||||
\$cache\_lifetime {#variable.cache.lifetime}
|
||||
=================
|
||||
|
||||
This is the length of time in seconds that a template cache is valid.
|
||||
Once this time has expired, the cache will be regenerated.
|
||||
|
||||
- `$caching` must be turned on (either
|
||||
Smarty::CACHING\_LIFETIME\_CURRENT or
|
||||
Smarty::CACHING\_LIFETIME\_SAVED) for `$cache_lifetime` to have any
|
||||
purpose.
|
||||
|
||||
- A `$cache_lifetime` value of -1 will force the cache to never
|
||||
expire.
|
||||
|
||||
- A value of 0 will cause the cache to always regenerate (good for
|
||||
testing only, to disable caching a more efficient method is to set
|
||||
[`$caching`](#variable.caching) = Smarty::CACHING\_OFF).
|
||||
|
||||
- If you want to give certain templates their own cache lifetime, you
|
||||
could do this by setting [`$caching`](#variable.caching) =
|
||||
Smarty::CACHING\_LIFETIME\_SAVED, then set `$cache_lifetime` to a
|
||||
unique value just before calling [`display()`](#api.display) or
|
||||
[`fetch()`](#api.fetch).
|
||||
|
||||
If [`$force_compile`](#variable.force.compile) is enabled, the cache
|
||||
files will be regenerated every time, effectively disabling caching. You
|
||||
can clear all the cache files with the
|
||||
[`clear_all_cache()`](#api.clear.all.cache) function, or individual
|
||||
cache files (or groups) with the [`clear_cache()`](#api.clear.cache)
|
||||
function.
|
11
docs/programmers/api-variables/variable-cache-locking.md
Normal file
11
docs/programmers/api-variables/variable-cache-locking.md
Normal file
@ -0,0 +1,11 @@
|
||||
\$cache\_locking {#variable.cache.locking}
|
||||
================
|
||||
|
||||
Cache locking avoids concurrent cache generation. This means resource
|
||||
intensive pages can be generated only once, even if they\'ve been
|
||||
requested multiple times in the same moment.
|
||||
|
||||
Cache locking is disabled by default. To enable it set `$cache_locking`
|
||||
to TRUE.
|
||||
|
||||
See also [`$locking_timeout`](#variable.locking.timeout)
|
@ -0,0 +1,12 @@
|
||||
\$cache\_modified\_check {#variable.cache.modified.check}
|
||||
========================
|
||||
|
||||
If set to TRUE, Smarty will respect the If-Modified-Since header sent
|
||||
from the client. If the cached file timestamp has not changed since the
|
||||
last visit, then a `'304: Not Modified'` header will be sent instead of
|
||||
the content. This works only on cached content without
|
||||
[`{insert}`](#language.function.insert) tags.
|
||||
|
||||
See also [`$caching`](#variable.caching),
|
||||
[`$cache_lifetime`](#variable.cache.lifetime), and the [caching
|
||||
section](#caching).
|
9
docs/programmers/api-variables/variable-caching-type.md
Normal file
9
docs/programmers/api-variables/variable-caching-type.md
Normal file
@ -0,0 +1,9 @@
|
||||
\$caching\_type {#variable.caching.type}
|
||||
===============
|
||||
|
||||
This property specifies the name of the caching handler to use. It
|
||||
defaults to `file`, enabling the internal filesystem based cache
|
||||
handler.
|
||||
|
||||
See [Custom Cache Implementation](#caching.custom) for pointers on
|
||||
setting up your own cache handler.
|
38
docs/programmers/api-variables/variable-caching.md
Normal file
38
docs/programmers/api-variables/variable-caching.md
Normal file
@ -0,0 +1,38 @@
|
||||
\$caching {#variable.caching}
|
||||
=========
|
||||
|
||||
This tells Smarty whether or not to cache the output of the templates to
|
||||
the [`$cache_dir`](#variable.cache.dir). By default this is set to the
|
||||
constant Smarty::CACHING\_OFF. If your templates consistently generate
|
||||
the same content, it is advisable to turn on `$caching`, as this may
|
||||
result in significant performance gains.
|
||||
|
||||
You can also have [multiple](#caching.multiple.caches) caches for the
|
||||
same template.
|
||||
|
||||
- A constant value of Smarty::CACHING\_LIFETIME\_CURRENT or
|
||||
Smarty::CACHING\_LIFETIME\_SAVED enables caching.
|
||||
|
||||
- A value of Smarty::CACHING\_LIFETIME\_CURRENT tells Smarty to use
|
||||
the current [`$cache_lifetime`](#variable.cache.lifetime) variable
|
||||
to determine if the cache has expired.
|
||||
|
||||
- A value of Smarty::CACHING\_LIFETIME\_SAVED tells Smarty to use the
|
||||
[`$cache_lifetime`](#variable.cache.lifetime) value at the time the
|
||||
cache was generated. This way you can set the
|
||||
[`$cache_lifetime`](#variable.cache.lifetime) just before
|
||||
[fetching](#api.fetch) the template to have granular control over
|
||||
when that particular cache expires. See also
|
||||
[`isCached()`](#api.is.cached).
|
||||
|
||||
- If [`$compile_check`](#variable.compile.check) is enabled, the
|
||||
cached content will be regenerated if any of the templates or config
|
||||
files that are part of this cache are changed.
|
||||
|
||||
- If [`$force_compile`](#variable.force.compile) is enabled, the
|
||||
cached content will always be regenerated.
|
||||
|
||||
See also [`$cache_dir`](#variable.cache.dir),
|
||||
[`$cache_lifetime`](#variable.cache.lifetime),
|
||||
[`$cache_modified_check`](#variable.cache.modified.check),
|
||||
[`is_cached()`](#api.is.cached) and the [caching section](#caching).
|
27
docs/programmers/api-variables/variable-compile-check.md
Normal file
27
docs/programmers/api-variables/variable-compile-check.md
Normal file
@ -0,0 +1,27 @@
|
||||
\$compile\_check {#variable.compile.check}
|
||||
================
|
||||
|
||||
Upon each invocation of the PHP application, Smarty tests to see if the
|
||||
current template has changed (different timestamp) since the last time
|
||||
it was compiled. If it has changed, it recompiles that template. If the
|
||||
template has yet not been compiled at all, it will compile regardless of
|
||||
this setting. By default this variable is set to TRUE.
|
||||
|
||||
Once an application is put into production (ie the templates won\'t be
|
||||
changing), the compile check step is no longer needed. Be sure to set
|
||||
`$compile_check` to FALSE for maximum performance. Note that if you
|
||||
change this to FALSE and a template file is changed, you will \*not\*
|
||||
see the change since the template will not get recompiled.
|
||||
|
||||
If [`$caching`](#variable.caching) is enabled and `$compile_check` is
|
||||
enabled, then the cache files will get regenerated if an involved
|
||||
template file or config file was updated.
|
||||
|
||||
As of Smarty 3.1 `$compile_check` can be set to the value
|
||||
`Smarty::COMPILECHECK_CACHEMISS`. This enables Smarty to revalidate the
|
||||
compiled template, once a cache file is regenerated. So if there was a
|
||||
cached template, but it\'s expired, Smarty will run a single
|
||||
compile\_check before regenerating the cache.
|
||||
|
||||
See [`$force_compile`](#variable.force.compile) and
|
||||
[`clearCompiledTemplate()`](#api.clear.compiled.tpl).
|
29
docs/programmers/api-variables/variable-compile-dir.md
Normal file
29
docs/programmers/api-variables/variable-compile-dir.md
Normal file
@ -0,0 +1,29 @@
|
||||
\$compile\_dir {#variable.compile.dir}
|
||||
==============
|
||||
|
||||
This is the name of the directory where compiled templates are located.
|
||||
By default this is `./templates_c`, meaning that Smarty will look for
|
||||
the `templates_c/` directory in the same directory as the executing php
|
||||
script. **This directory must be writeable by the web server**, [see
|
||||
install](#installing.smarty.basic) for more info.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> This setting must be either a relative or absolute path. include\_path
|
||||
> is not used for writing files.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> It is not recommended to put this directory under the web server
|
||||
> document root.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> As of Smarty 3.1 the attribute \$compile\_dir is no longer accessible
|
||||
> directly. Use [`getCompileDir()`](#api.get.compile.dir) and
|
||||
> [`setCompileDir()`](#api.set.compile.dir) instead.
|
||||
|
||||
See also [`getCompileDir()`](#api.get.compile.dir),
|
||||
[`setCompileDir()`](#api.set.compile.dir),
|
||||
[`$compile_id`](#variable.compile.id) and
|
||||
[`$use_sub_dirs`](#variable.use.sub.dirs).
|
44
docs/programmers/api-variables/variable-compile-id.md
Normal file
44
docs/programmers/api-variables/variable-compile-id.md
Normal file
@ -0,0 +1,44 @@
|
||||
\$compile\_id {#variable.compile.id}
|
||||
=============
|
||||
|
||||
Persistant compile identifier. As an alternative to passing the same
|
||||
`$compile_id` to each and every function call, you can set this
|
||||
`$compile_id` and it will be used implicitly thereafter.
|
||||
|
||||
If you use the same template with different [pre- and/or
|
||||
post-filters](#plugins.prefilters.postfilters) you must use a unique
|
||||
`$compile_id` to keep the compiled template files separated.
|
||||
|
||||
For example a [prefilter](#plugins.prefilters.postfilters) that
|
||||
localizes your templates (that is: translates language dependend parts)
|
||||
at compile time, then you could use the current language as
|
||||
`$compile_id` and you will get a set of compiled templates for each
|
||||
language you use.
|
||||
|
||||
|
||||
<?php
|
||||
$smarty->compile_id = 'en';
|
||||
?>
|
||||
|
||||
|
||||
|
||||
Another application would be to use the same compile directory across
|
||||
multiple domains / multiple virtual hosts.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty->compile_id = $_SERVER['SERVER_NAME'];
|
||||
$smarty->compile_dir = '/path/to/shared_compile_dir';
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> In Smarty 3 a `$compile_id` is no longer required to keep templates
|
||||
> with same name in different [`$template_dir`
|
||||
> folders](#variable.template.dir) separated. The [`$template_dir` file
|
||||
> path](#variable.template.dir) is encoded in the file name of compiled
|
||||
> and cached template files.
|
@ -0,0 +1,7 @@
|
||||
\$compile\_locking {#variable.compile.locking}
|
||||
==================
|
||||
|
||||
Compile locking avoids concurrent compilation of the same template.
|
||||
|
||||
Compile locking is enabled by default. To disable it set
|
||||
`$compile_locking` to FALSE.
|
@ -0,0 +1,6 @@
|
||||
\$compiler\_class {#variable.compiler.class}
|
||||
=================
|
||||
|
||||
Specifies the name of the compiler class that Smarty will use to compile
|
||||
the templates. The default is \'Smarty\_Compiler\'. For advanced users
|
||||
only.
|
@ -0,0 +1,8 @@
|
||||
\$config\_booleanize {#variable.config.booleanize}
|
||||
====================
|
||||
|
||||
If set to TRUE, [config files](#config.files) values of `on/true/yes`
|
||||
and `off/false/no` get converted to boolean values automatically. This
|
||||
way you can use the values in the template like so:
|
||||
`{if #foobar#}...{/if}`. If foobar was `on`, `true` or `yes`, the `{if}`
|
||||
statement will execute. Defaults to TRUE.
|
23
docs/programmers/api-variables/variable-config-dir.md
Normal file
23
docs/programmers/api-variables/variable-config-dir.md
Normal file
@ -0,0 +1,23 @@
|
||||
\$config\_dir {#variable.config.dir}
|
||||
=============
|
||||
|
||||
This is the directory used to store [config files](#config.files) used
|
||||
in the templates. Default is `./configs`, meaning that Smarty will look
|
||||
for the `configs/` directory in the same directory as the executing php
|
||||
script.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> It is not recommended to put this directory under the web server
|
||||
> document root.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> As of Smarty 3.1 the attribute \$config\_dir is no longer accessible
|
||||
> directly. Use [`getConfigDir()`](#api.get.config.dir),
|
||||
> [`setConfigDir()`](#api.set.config.dir) and
|
||||
> [`addConfigDir()`](#api.add.config.dir) instead.
|
||||
|
||||
See also [`getConfigDir()`](#api.get.config.dir),
|
||||
[`setConfigDir()`](#api.set.config.dir) and
|
||||
[`addConfigDir()`](#api.add.config.dir).
|
40
docs/programmers/api-variables/variable-config-overwrite.md
Normal file
40
docs/programmers/api-variables/variable-config-overwrite.md
Normal file
@ -0,0 +1,40 @@
|
||||
\$config\_overwrite {#variable.config.overwrite}
|
||||
===================
|
||||
|
||||
If set to TRUE, the default then variables read in from [config
|
||||
files](#config.files) will overwrite each other. Otherwise, the
|
||||
variables will be pushed onto an array. This is helpful if you want to
|
||||
store arrays of data in config files, just list each element multiple
|
||||
times.
|
||||
|
||||
This examples uses [`{cycle}`](#language.function.cycle) to output a
|
||||
table with alternating red/green/blue row colors with
|
||||
`$config_overwrite` = FALSE.
|
||||
|
||||
The config file.
|
||||
|
||||
|
||||
# row colors
|
||||
rowColors = #FF0000
|
||||
rowColors = #00FF00
|
||||
rowColors = #0000FF
|
||||
|
||||
|
||||
|
||||
The template with a [`{section}`](#language.function.section) loop.
|
||||
|
||||
|
||||
<table>
|
||||
{section name=r loop=$rows}
|
||||
<tr bgcolor="{cycle values=#rowColors#}">
|
||||
<td> ....etc.... </td>
|
||||
</tr>
|
||||
{/section}
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
See also [`{config_load}`](#language.function.config.load),
|
||||
[`getConfigVars()`](#api.get.config.vars),
|
||||
[`clearConfig()`](#api.clear.config), [`configLoad()`](#api.config.load)
|
||||
and the [config files section](#config.files).
|
@ -0,0 +1,8 @@
|
||||
\$config\_read\_hidden {#variable.config.read.hidden}
|
||||
======================
|
||||
|
||||
If set to TRUE, hidden sections ie section names beginning with a
|
||||
period(.) in [config files](#config.files) can be read from templates.
|
||||
Typically you would leave this FALSE, that way you can store sensitive
|
||||
data in the config files such as database parameters and not worry about
|
||||
the template loading them. FALSE by default.
|
@ -0,0 +1,9 @@
|
||||
\$debug\_tpl {#variable.debug_template}
|
||||
============
|
||||
|
||||
This is the name of the template file used for the debugging console. By
|
||||
default, it is named `debug.tpl` and is located in the
|
||||
[`SMARTY_DIR`](#constant.smarty.dir).
|
||||
|
||||
See also [`$debugging`](#variable.debugging) and the [debugging
|
||||
console](#chapter.debugging.console) section.
|
20
docs/programmers/api-variables/variable-debugging-ctrl.md
Normal file
20
docs/programmers/api-variables/variable-debugging-ctrl.md
Normal file
@ -0,0 +1,20 @@
|
||||
\$debugging\_ctrl {#variable.debugging.ctrl}
|
||||
=================
|
||||
|
||||
This allows alternate ways to enable debugging. `NONE` means no
|
||||
alternate methods are allowed. `URL` means when the keyword
|
||||
`SMARTY_DEBUG` is found in the `QUERY_STRING`, debugging is enabled for
|
||||
that invocation of the script. If [`$debugging`](#variable.debugging) is
|
||||
TRUE, this value is ignored.
|
||||
|
||||
|
||||
<?php
|
||||
// shows debug console only on localhost ie
|
||||
// http://localhost/script.php?foo=bar&SMARTY_DEBUG
|
||||
$smarty->debugging = false; // the default
|
||||
$smarty->debugging_ctrl = ($_SERVER['SERVER_NAME'] == 'localhost') ? 'URL' : 'NONE';
|
||||
?>
|
||||
|
||||
See also [debugging console](#chapter.debugging.console) section,
|
||||
[`$debugging`](#variable.debugging) and
|
||||
[`$smarty_debug_id`](#variable.smarty.debug.id).
|
17
docs/programmers/api-variables/variable-debugging.md
Normal file
17
docs/programmers/api-variables/variable-debugging.md
Normal file
@ -0,0 +1,17 @@
|
||||
\$debugging {#variable.debugging}
|
||||
===========
|
||||
|
||||
This enables the [debugging console](#chapter.debugging.console). The
|
||||
console is a javascript popup window that informs you of the
|
||||
[included](#language.function.include) templates, variables
|
||||
[assigned](#api.assign) from php and [config file
|
||||
variables](#language.config.variables) for the current script. It does
|
||||
not show variables assigned within a template with the
|
||||
[`{assign}`](#language.function.assign) function.
|
||||
|
||||
The console can also be enabled from the url with
|
||||
[`$debugging_ctrl`](#variable.debugging.ctrl).
|
||||
|
||||
See also [`{debug}`](#language.function.debug),
|
||||
[`$debug_tpl`](#variable.debug_template), and
|
||||
[`$debugging_ctrl`](#variable.debugging.ctrl).
|
@ -0,0 +1,50 @@
|
||||
\$default\_config\_handler\_func {#variable.default.config.handler.func}
|
||||
================================
|
||||
|
||||
This function is called when a config file cannot be obtained from its
|
||||
resource.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> The default handler is currently only invoked for file resources. It
|
||||
> is not triggered when the resource itself cannot be found, in which
|
||||
> case a SmartyException is thrown.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty = new Smarty();
|
||||
$smarty->default_config_handler_func = 'my_default_config_handler_func';
|
||||
|
||||
/**
|
||||
* Default Config Handler
|
||||
*
|
||||
* called when Smarty's file: resource is unable to load a requested file
|
||||
*
|
||||
* @param string $type resource type (e.g. "file", "string", "eval", "resource")
|
||||
* @param string $name resource name (e.g. "foo/bar.tpl")
|
||||
* @param string &$content config's content
|
||||
* @param integer &$modified config's modification time
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @return string|boolean path to file or boolean true if $content and $modified
|
||||
* have been filled, boolean false if no default config
|
||||
* could be loaded
|
||||
*/
|
||||
function my_default_config_handler_func($type, $name, &$content, &$modified, Smarty $smarty) {
|
||||
if (false) {
|
||||
// return corrected filepath
|
||||
return "/tmp/some/foobar.tpl";
|
||||
} elseif (false) {
|
||||
// return a config directly
|
||||
$content = 'someVar = "the config source"';
|
||||
$modified = time();
|
||||
return true;
|
||||
} else {
|
||||
// tell smarty that we failed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
\$default\_config\_type {#variable.default.config.type}
|
||||
=======================
|
||||
|
||||
This tells smarty what resource type to use for config files. The
|
||||
default value is `file`, meaning that `$smarty->configLoad('test.conf')`
|
||||
and `$smarty->configLoad('file:test.conf')` are identical in meaning.
|
||||
See the [resource](#resources) chapter for more details.
|
@ -0,0 +1,8 @@
|
||||
\$default\_modifiers {#variable.default.modifiers}
|
||||
====================
|
||||
|
||||
This is an array of modifiers to implicitly apply to every variable in a
|
||||
template. For example, to HTML-escape every variable by default, use
|
||||
`array('escape:"htmlall"')`. To make a variable exempt from default
|
||||
modifiers, add the \'nofilter\' attribute to the output tag such as
|
||||
`{$var nofilter}`.
|
@ -0,0 +1,7 @@
|
||||
\$default\_resource\_type {#variable.default.resource.type}
|
||||
=========================
|
||||
|
||||
This tells smarty what resource type to use implicitly. The default
|
||||
value is `file`, meaning that `$smarty->display('index.tpl')` and
|
||||
`$smarty->display('file:index.tpl')` are identical in meaning. See the
|
||||
[resource](#resources) chapter for more details.
|
@ -0,0 +1,50 @@
|
||||
\$default\_template\_handler\_func {#variable.default.template.handler.func}
|
||||
==================================
|
||||
|
||||
This function is called when a template cannot be obtained from its
|
||||
resource.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> The default handler is currently only invoked for file resources. It
|
||||
> is not triggered when the resource itself cannot be found, in which
|
||||
> case a SmartyException is thrown.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$smarty = new Smarty();
|
||||
$smarty->default_template_handler_func = 'my_default_template_handler_func';
|
||||
|
||||
/**
|
||||
* Default Template Handler
|
||||
*
|
||||
* called when Smarty's file: resource is unable to load a requested file
|
||||
*
|
||||
* @param string $type resource type (e.g. "file", "string", "eval", "resource")
|
||||
* @param string $name resource name (e.g. "foo/bar.tpl")
|
||||
* @param string &$content template's content
|
||||
* @param integer &$modified template's modification time
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @return string|boolean path to file or boolean true if $content and $modified
|
||||
* have been filled, boolean false if no default template
|
||||
* could be loaded
|
||||
*/
|
||||
function my_default_template_handler_func($type, $name, &$content, &$modified, Smarty $smarty) {
|
||||
if (false) {
|
||||
// return corrected filepath
|
||||
return "/tmp/some/foobar.tpl";
|
||||
} elseif (false) {
|
||||
// return a template directly
|
||||
$content = "the template source";
|
||||
$modified = time();
|
||||
return true;
|
||||
} else {
|
||||
// tell smarty that we failed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
\$direct\_access\_security {#variable.direct.access.security}
|
||||
==========================
|
||||
|
||||
Direct access security inhibits direct browser access to compiled or
|
||||
cached template files.
|
||||
|
||||
Direct access security is enabled by default. To disable it set
|
||||
`$direct_access_security` to FALSE.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> This is a compile time option. If you change the setting you must make
|
||||
> sure that the templates get recompiled.
|
17
docs/programmers/api-variables/variable-error-reporting.md
Normal file
17
docs/programmers/api-variables/variable-error-reporting.md
Normal file
@ -0,0 +1,17 @@
|
||||
\$error\_reporting {#variable.error.reporting}
|
||||
==================
|
||||
|
||||
When this value is set to a non-null-value it\'s value is used as php\'s
|
||||
[`error_reporting`](&url.php-manual;error_reporting) level inside of
|
||||
[`display()`](#api.display) and [`fetch()`](#api.fetch).
|
||||
|
||||
Smarty 3.1.2 introduced the
|
||||
[`muteExpectedErrors()`](#api.mute.expected.errors) function. Calling
|
||||
`Smarty::muteExpectedErrors();` after setting up custom error handling
|
||||
will ensure that warnings and notices (deliberately) produced by Smarty
|
||||
will not be passed to other custom error handlers. If your error logs
|
||||
are filling up with warnings regarding `filemtime()` or `unlink()`
|
||||
calls, please enable Smarty\'s error muting.
|
||||
|
||||
See also [debugging](#chapter.debugging.console) and
|
||||
[troubleshooting](#troubleshooting).
|
21
docs/programmers/api-variables/variable-escape-html.md
Normal file
21
docs/programmers/api-variables/variable-escape-html.md
Normal file
@ -0,0 +1,21 @@
|
||||
\$escape\_html {#variable.escape.html}
|
||||
==============
|
||||
|
||||
Setting `$escape_html` to TRUE will escape all template variable output
|
||||
by wrapping it in
|
||||
`htmlspecialchars({$output}, ENT_QUOTES, SMARTY_RESOURCE_CHAR_SET);`,
|
||||
which is the same as `{$variable|escape:"html"}`.
|
||||
|
||||
Template designers can choose to selectively disable this feature by
|
||||
adding the `nofilter` flag: `{$variable nofilter}`.
|
||||
|
||||
Modifiers and Filters are run in the following order: modifier,
|
||||
default\_modifier, \$escape\_html, registered variable filters,
|
||||
autoloaded variable filters, template instance\'s variable filters.
|
||||
Everything except the individual modifier can be disabled with the
|
||||
`nofilter` flag.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> This is a compile time option. If you change the setting you must make
|
||||
> sure that the templates get recompiled.
|
6
docs/programmers/api-variables/variable-force-cache.md
Normal file
6
docs/programmers/api-variables/variable-force-cache.md
Normal file
@ -0,0 +1,6 @@
|
||||
\$force\_cache {#variable.force.cache}
|
||||
==============
|
||||
|
||||
This forces Smarty to (re)cache templates on every invocation. It does
|
||||
not override the [`$caching`](#variable.caching) level, but merely
|
||||
pretends the template has never been cached before.
|
9
docs/programmers/api-variables/variable-force-compile.md
Normal file
9
docs/programmers/api-variables/variable-force-compile.md
Normal file
@ -0,0 +1,9 @@
|
||||
\$force\_compile {#variable.force.compile}
|
||||
================
|
||||
|
||||
This forces Smarty to (re)compile templates on every invocation. This
|
||||
setting overrides [`$compile_check`](#variable.compile.check). By
|
||||
default this is FALSE. This is handy for development and
|
||||
[debugging](#chapter.debugging.console). It should never be used in a
|
||||
production environment. If [`$caching`](#variable.caching) is enabled,
|
||||
the cache file(s) will be regenerated every time.
|
@ -0,0 +1,8 @@
|
||||
\$left\_delimiter {#variable.left.delimiter}
|
||||
=================
|
||||
|
||||
This is the left delimiter used by the template language. Default is
|
||||
`{`.
|
||||
|
||||
See also [`$right_delimiter`](#variable.right.delimiter) and [escaping
|
||||
smarty parsing](#language.escaping) .
|
@ -0,0 +1,7 @@
|
||||
\$locking\_timeout {#variable.locking.timeout}
|
||||
==================
|
||||
|
||||
This is maximum time in seconds a cache lock is valid to avoid dead
|
||||
locks. The deafult value is 10 seconds.
|
||||
|
||||
See also [`$cache_locking`](#variable.cache.locking)
|
@ -0,0 +1,27 @@
|
||||
\$merge\_compiled\_includes {#variable.merge.compiled.includes}
|
||||
===========================
|
||||
|
||||
By setting `$merge_compiled_includes` to TRUE Smarty will merge the
|
||||
compiled template code of subtemplates into the compiled code of the
|
||||
main template. This increases rendering speed of templates using a many
|
||||
different sub-templates.
|
||||
|
||||
Individual sub-templates can be merged by setting the `inline` option
|
||||
flag within the `{include}` tag. `$merge_compiled_includes` does not
|
||||
have to be enabled for the `inline` merge.
|
||||
|
||||
::: {.informalexample}
|
||||
|
||||
<?php
|
||||
$smarty->merge_compiled_includes = true;
|
||||
?>
|
||||
|
||||
|
||||
:::
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> This is a compile time option. If you change the setting you must make
|
||||
> sure that the templates get recompiled.
|
||||
|
||||
See also [`{include}`](#language.function.include) tag
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user