mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 11:54:26 +02:00
update documentation, remove tests from index file and template
This commit is contained in:
@@ -4,8 +4,6 @@ require("Smarty.class.php");
|
||||
|
||||
$smarty = new Smarty;
|
||||
|
||||
$smarty->caching = false;
|
||||
|
||||
$smarty->assign(now, time());
|
||||
|
||||
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
|
||||
@@ -19,11 +17,4 @@ $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" =>
|
||||
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
function insert_foo($args)
|
||||
{
|
||||
extract($args);
|
||||
|
||||
return "test $arg1";
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -46,9 +46,3 @@ testing strip tags
|
||||
{/strip}
|
||||
|
||||
</PRE>
|
||||
|
||||
{insert name = foo
|
||||
arg1=$now arg2=true}
|
||||
|
||||
test: {$now|date_format:"%I:%M %p"}
|
||||
|
||||
|
274
docs.sgml
274
docs.sgml
@@ -129,19 +129,30 @@
|
||||
discussed later in this document.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2><title>Caching</title>
|
||||
<sect2 id="section.caching">
|
||||
<title>Caching</title>
|
||||
<para>
|
||||
Smarty can cache the output of your generated templates. By default
|
||||
this is disabled. If you enable caching, Smarty will store a copy
|
||||
of the generated template output, and use this until the copy
|
||||
expires, regenerating a new one. If your templates generate the
|
||||
same content over and over, using the cache will result in huge
|
||||
performance gains. The default cache expire time is one hour, and
|
||||
can be configured from the class. The exception to the rule is the
|
||||
<link linkend="function.insert">insert</link> tag. Anything
|
||||
generated by the insert tag is not cached, but run dynamically on
|
||||
every invocation, even within cached content.
|
||||
Smarty can cache the output of your generated templates. By default
|
||||
this is disabled. If you <link linkend="setting.caching">enable
|
||||
caching</link>, Smarty will store a copy of the generated template
|
||||
output, and use this until the copy <link
|
||||
linkend="setting.cache.lifetime">expires</link>, regenerating a new
|
||||
one. The default cache expire time is one hour, and can be
|
||||
configured from the class. The exception to the rule is the <link
|
||||
linkend="function.insert">insert</link> tag. Anything generated by
|
||||
the insert tag is not cached, but run dynamically on every
|
||||
invocation, even within cached content.
|
||||
</para>
|
||||
<para>
|
||||
TECHNICAL NOTE: Any time you change a template, change values in
|
||||
config files or change the content that gets displayed in a
|
||||
template, you must either clear the caches that are affected, or
|
||||
wait for the cache to expire to see the results of the changes. You
|
||||
can either do this manually by deleting files from the cache
|
||||
directory, or programatically with <link
|
||||
linkend="api.clear.cache">clear_cache</link> or <link
|
||||
linkend="api.clear.all.cache">clear_all_cache</link>.
|
||||
</para>
|
||||
</sect2>
|
||||
</sect1>
|
||||
</chapter>
|
||||
@@ -208,6 +219,37 @@ chmod 700 cache
|
||||
<sect1>
|
||||
<title>Configuration variables</title>
|
||||
<para></para>
|
||||
<sect2 id="setting.template.dir">
|
||||
<title>$template_dir</title>
|
||||
<para>
|
||||
This is the name of the directory where template files are located.
|
||||
By default this is "./templates".
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.compile.dir">
|
||||
<title>$compile_dir</title>
|
||||
<para>
|
||||
This is the name of the directory where compiled templates are
|
||||
located. By default this is "./templates_c". This was
|
||||
added to Smarty version 1.2.1.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.config.dir">
|
||||
<title>$config_dir</title>
|
||||
<para>
|
||||
This is the directory used to store config files used in the templates.
|
||||
Default is "configs".
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.global.assign">
|
||||
<title>$global_assign</title>
|
||||
<para>
|
||||
This is a list of variables that are always implicitly assigned to the
|
||||
template engine. This is usually handy for making global variables or server
|
||||
variables available to the template without having to manually assign them to
|
||||
the template every time.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>$compile_check</title>
|
||||
<para>
|
||||
@@ -249,6 +291,14 @@ chmod 700 cache
|
||||
undesireable results. This was added to Smarty 1.3.0.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.cache.dir">
|
||||
<title>$cache_dir</title>
|
||||
<para>
|
||||
This is the name of the directory where template caches are
|
||||
located. By default this is "./cache". This was
|
||||
added to Smarty version 1.3.0.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.cache.lifetime">
|
||||
<title>$cache_lifetime</title>
|
||||
<para>
|
||||
@@ -260,40 +310,7 @@ chmod 700 cache
|
||||
added to Smarty 1.3.0.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="template.dir">
|
||||
<title>$template_dir</title>
|
||||
<para>
|
||||
This is the name of the directory where template files are located.
|
||||
By default this is "./templates".
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>$compile_dir</title>
|
||||
<para>
|
||||
This is the name of the directory where compiled templates are
|
||||
located. By default this is "./templates_c". This was
|
||||
added to Smarty version 1.2.1.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>$cache_dir</title>
|
||||
<para>
|
||||
This is the name of the directory where template caches are
|
||||
located. By default this is "./cache". This was
|
||||
added to Smarty version 1.3.0.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>$compile_dir_ext</title>
|
||||
<para>
|
||||
This is the extension used for the name of the directory where
|
||||
compiled templates are located. By default this is "_c".
|
||||
Therefore if your template directory is named "templates", then
|
||||
the compiled templates directory will be named "templates_c".
|
||||
NOTE: this was removed from Smarty version 1.2.1.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="setting.tpl.file.ext">
|
||||
<title>$tpl_file_ext</title>
|
||||
<para>
|
||||
This is the extention used for template files. By default this
|
||||
@@ -301,7 +318,7 @@ chmod 700 cache
|
||||
ignored.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="setting.allow.php">
|
||||
<title>$allow_php</title>
|
||||
<para>
|
||||
Whether or not to allow PHP code in the templates. If set to
|
||||
@@ -312,26 +329,19 @@ chmod 700 cache
|
||||
is "false".
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="setting.left.delimiter">
|
||||
<title>$left_delimiter</title>
|
||||
<para>
|
||||
This is the left delimiter used by the template language. Default is "{".
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="setting.right.delimiter">
|
||||
<title>$right_delimiter</title>
|
||||
<para>
|
||||
This is the right delimiter used by the template language. Default is "}".
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>$config_dir</title>
|
||||
<para>
|
||||
This is the directory used to store config files used in the templates.
|
||||
Default is "configs".
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="setting.custom.funcs">
|
||||
<title>$custom_funcs</title>
|
||||
<para>
|
||||
This is a mapping of the names of <link
|
||||
@@ -339,7 +349,7 @@ chmod 700 cache
|
||||
the names of functions in PHP. These are usually kept in Smarty.addons.php.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="setting.custom.mods">
|
||||
<title>$custom_mods</title>
|
||||
<para>
|
||||
This is a mapping of the names of variable
|
||||
@@ -347,15 +357,6 @@ chmod 700 cache
|
||||
the names of functions in PHP. These are usually kept in Smarty.addons.php.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>$global_assign</title>
|
||||
<para>
|
||||
This is a list of variables that are always implicitly assigned to the
|
||||
template engine. This is usually handy for making global variables or server
|
||||
variables available to the template without having to manually assign them to
|
||||
the template every time.
|
||||
</para>
|
||||
</sect2>
|
||||
</sect1>
|
||||
</chapter>
|
||||
<chapter>
|
||||
@@ -365,7 +366,7 @@ chmod 700 cache
|
||||
</para>
|
||||
<sect1>
|
||||
<title>Smarty API Functions</title>
|
||||
<sect2>
|
||||
<sect2 id="api.assign">
|
||||
<title>assign</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
@@ -385,7 +386,7 @@ chmod 700 cache
|
||||
data gathered from database queries or other sources of data.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="api.append">
|
||||
<title>append</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
@@ -404,7 +405,7 @@ chmod 700 cache
|
||||
This is used to append data to existing variables in the template.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="api.clear.assign">
|
||||
<title>clear_assign</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
@@ -416,7 +417,7 @@ chmod 700 cache
|
||||
This clears the value of an assigned variable.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="api.clear.all.assign">
|
||||
<title>clear_all_assign</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
@@ -428,6 +429,83 @@ chmod 700 cache
|
||||
This clears the values of all assigned variables.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="api.register.function">
|
||||
<title>register_function</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>void <function>register_function</function></funcdef>
|
||||
<paramdef>string <parameter>funcname</parameter></paramdef>
|
||||
<paramdef>string <parameter>funcimpl</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
Use this to dynamically register functions with Smarty. Pass in
|
||||
the Smarty function name, followed by the actual function name
|
||||
that it is mapped to.
|
||||
</para>
|
||||
<example>
|
||||
<title>register_function</title>
|
||||
<programlisting>
|
||||
|
||||
$smarty->register_function("date_now","print_current_date");
|
||||
|
||||
function print_current_date ($params) {
|
||||
extract($params);
|
||||
if(empty($format))
|
||||
$format="%b %e, %Y";
|
||||
echo strftime($format,time());
|
||||
}
|
||||
|
||||
// now you can use this in Smarty to print the current date: {date_now}
|
||||
// or, {date_now format="%Y/%m/%d"} to format it.
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="api.register.modifier">
|
||||
<title>register_modifier</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>void <function>register_modifier</function></funcdef>
|
||||
<paramdef>string <parameter>modname</parameter></paramdef>
|
||||
<paramdef>string <parameter>funcimpl</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
Use this to dynamically register modifiers with Smarty. Pass in
|
||||
the Smarty modifier name, followed by the actual function name
|
||||
that it is mapped to.
|
||||
</para>
|
||||
<example>
|
||||
<title>register_modifier</title>
|
||||
<programlisting>
|
||||
|
||||
// let's map PHP's stripslashes function to a Smarty modifier.
|
||||
|
||||
$smarty->register_modifier("sslash","stripslashes");
|
||||
|
||||
// now you can use {$var|sslash} to strip slashes from variables
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="api.clear.cache">
|
||||
<title>clear_cache</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>void <function>clear_cache</function></funcdef>
|
||||
<paramdef>string <parameter>template</parameter></paramdef>
|
||||
<paramdef>string <parameter>cache id</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This clears the cache. For the specified template. If you have
|
||||
multiple caches for this template, you can clear a specific
|
||||
cache by supplying the cache id as the second parameter. See the
|
||||
<link linkend="section.caching">caching section</link> for more
|
||||
information. This was added to Smarty 1.3.0.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="api.clear.all.cache">
|
||||
<title>clear_all_cache</title>
|
||||
<funcsynopsis>
|
||||
@@ -451,12 +529,10 @@ chmod 700 cache
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This returns true if there is a valid cache for this template.
|
||||
Use this to skip process-intensive tasks that aren't necessary
|
||||
when a cached version of the template is available. This was
|
||||
added to Smarty 1.3.0.
|
||||
This was added to Smarty 1.3.0.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="api.get.template.vars">
|
||||
<title>get_template_vars</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
@@ -468,20 +544,24 @@ chmod 700 cache
|
||||
This gets an array of the currently assigned template vars.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="api.display">
|
||||
<title>display</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>void <function>display</function></funcdef>
|
||||
<paramdef>string <parameter>template</parameter></paramdef>
|
||||
<paramdef>string <parameter>cache id</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This displays the template. Supply a path relative to the
|
||||
<link linkend="template.dir">template directory</link>
|
||||
<link linkend="setting.template.dir">template directory</link>.
|
||||
As an optional second parameter, you can pass a cache id.
|
||||
See the <link linkend="section.caching">caching section</link> for
|
||||
more information.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<sect2 id="api.fetch">
|
||||
<title>fetch</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
@@ -491,13 +571,13 @@ chmod 700 cache
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This returns the template output. Supply a path relative to the
|
||||
<link linkend="template.dir">template directory</link>
|
||||
<link linkend="setting.template.dir">template directory</link>
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>Using Smarty API</title>
|
||||
<example>
|
||||
<title>Example use of Smarty API</title>
|
||||
<example>
|
||||
<title>Example use of Smarty API</title>
|
||||
<programlisting>
|
||||
|
||||
include("Smarty.class.php");
|
||||
@@ -528,7 +608,7 @@ $smarty->display("index.tpl");
|
||||
// alternatively capture the output
|
||||
// $output = $smarty->fetch("index.tpl");
|
||||
</programlisting>
|
||||
</example>
|
||||
</example>
|
||||
</sect2>
|
||||
</sect1>
|
||||
</chapter>
|
||||
@@ -943,12 +1023,12 @@ Intro = """This is a value that spans more
|
||||
and display the returned results in place of the insert tag.
|
||||
</para>
|
||||
<para>
|
||||
A note on caching: If you have <link
|
||||
linkend="setting.caching">caching</link> turned on, insert tags
|
||||
will not be cached. They will run dynamically every time the page
|
||||
is created, even within cached pages. This works good for things
|
||||
like banners, polls, live weather, search results, user feedback
|
||||
areas, etc.
|
||||
TECHNICAL NOTE: It is possible to have portions of the template not
|
||||
cached. If you have <link linkend="section.caching">caching</link>
|
||||
turned on, insert tags will not be cached. They will run
|
||||
dynamically every time the page is created, even within cached
|
||||
pages. This works good for things like banners, polls, live
|
||||
weather, search results, user feedback areas, etc.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2>
|
||||
@@ -2502,26 +2582,28 @@ function makeTimeStamp($year="",$month="",$day="")
|
||||
<chapter id="credits">
|
||||
<title>CREDITS</title>
|
||||
<para>
|
||||
Monte Ohrt <monte@ispi.net>: Idea of compiling into PHP scripts,
|
||||
initial implementation, documentation.
|
||||
Monte Ohrt <monte@ispi.net>: Concepted compiling templates into PHP
|
||||
scripts, wrote initial "proof of concept" implementation, and maintains
|
||||
documentation.
|
||||
</para>
|
||||
<para>
|
||||
Andrei Zmievski <andrei@ispi.net>: Rewrote parser from scratch, added
|
||||
custom modifier functionality, and much more.
|
||||
Andrei Zmievski <andrei@ispi.net>: Rewrote parser from scratch and
|
||||
added other features too numerous to mention.
|
||||
</para>
|
||||
<para>
|
||||
Anne Holz <anne@ispi.net>: Contributed several ideas for formatting features.
|
||||
Anne Holz <anne@ispi.net>: Many of Smarty's formatting features were
|
||||
a direct result of needs from her department.
|
||||
</para>
|
||||
<para>
|
||||
Frank Kromann <fmk@php.net>: Idea of custom function ability.
|
||||
</para>
|
||||
<para>
|
||||
A special thanks goes to all the people that have contributed other
|
||||
templating solutions to the PHP community which we learned a lot from.
|
||||
A special thanks goes to the people that have contributed other templating
|
||||
solutions to the PHP community which we learned a lot from.
|
||||
</para>
|
||||
<para>
|
||||
A special thanks goes to all the members of the php-template mailing list,
|
||||
who shared and brought many ideas to the table.
|
||||
A special thanks goes to the members of the php-template mailing list and
|
||||
the smarty mailing list, whom shared and brought many ideas to the table.
|
||||
</para>
|
||||
<para>
|
||||
Rasmus Lerdorf <rasmus@php.net>: For starting what eventually became
|
||||
|
@@ -4,8 +4,6 @@ require("Smarty.class.php");
|
||||
|
||||
$smarty = new Smarty;
|
||||
|
||||
$smarty->caching = false;
|
||||
|
||||
$smarty->assign(now, time());
|
||||
|
||||
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
|
||||
@@ -19,11 +17,4 @@ $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" =>
|
||||
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
function insert_foo($args)
|
||||
{
|
||||
extract($args);
|
||||
|
||||
return "test $arg1";
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -46,9 +46,3 @@ testing strip tags
|
||||
{/strip}
|
||||
|
||||
</PRE>
|
||||
|
||||
{insert name = foo
|
||||
arg1=$now arg2=true}
|
||||
|
||||
test: {$now|date_format:"%I:%M %p"}
|
||||
|
||||
|
Reference in New Issue
Block a user