update documentation, remove tests from index file and template

This commit is contained in:
mohrt
2001-02-07 23:09:32 +00:00
parent 08c386c2e6
commit d539f10a18
5 changed files with 178 additions and 126 deletions

View File

@@ -4,8 +4,6 @@ require("Smarty.class.php");
$smarty = new Smarty; $smarty = new Smarty;
$smarty->caching = false;
$smarty->assign(now, time()); $smarty->assign(now, time());
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill"); $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'); $smarty->display('index.tpl');
function insert_foo($args)
{
extract($args);
return "test $arg1";
}
?> ?>

View File

@@ -46,9 +46,3 @@ testing strip tags
{/strip} {/strip}
</PRE> </PRE>
{insert name = foo
arg1=$now arg2=true}
test: {$now|date_format:"%I:%M %p"}

274
docs.sgml
View File

@@ -129,19 +129,30 @@
discussed later in this document. discussed later in this document.
</para> </para>
</sect2> </sect2>
<sect2><title>Caching</title> <sect2 id="section.caching">
<title>Caching</title>
<para> <para>
Smarty can cache the output of your generated templates. By default Smarty can cache the output of your generated templates. By default
this is disabled. If you enable caching, Smarty will store a copy this is disabled. If you <link linkend="setting.caching">enable
of the generated template output, and use this until the copy caching</link>, Smarty will store a copy of the generated template
expires, regenerating a new one. If your templates generate the output, and use this until the copy <link
same content over and over, using the cache will result in huge linkend="setting.cache.lifetime">expires</link>, regenerating a new
performance gains. The default cache expire time is one hour, and one. The default cache expire time is one hour, and can be
can be configured from the class. The exception to the rule is the configured from the class. The exception to the rule is the <link
<link linkend="function.insert">insert</link> tag. Anything linkend="function.insert">insert</link> tag. Anything generated by
generated by the insert tag is not cached, but run dynamically on the insert tag is not cached, but run dynamically on every
every invocation, even within cached content. invocation, even within cached content.
</para> </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> </sect2>
</sect1> </sect1>
</chapter> </chapter>
@@ -208,6 +219,37 @@ chmod 700 cache
<sect1> <sect1>
<title>Configuration variables</title> <title>Configuration variables</title>
<para></para> <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> <sect2>
<title>$compile_check</title> <title>$compile_check</title>
<para> <para>
@@ -249,6 +291,14 @@ chmod 700 cache
undesireable results. This was added to Smarty 1.3.0. undesireable results. This was added to Smarty 1.3.0.
</para> </para>
</sect2> </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"> <sect2 id="setting.cache.lifetime">
<title>$cache_lifetime</title> <title>$cache_lifetime</title>
<para> <para>
@@ -260,40 +310,7 @@ chmod 700 cache
added to Smarty 1.3.0. added to Smarty 1.3.0.
</para> </para>
</sect2> </sect2>
<sect2 id="template.dir"> <sect2 id="setting.tpl.file.ext">
<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>
<title>$tpl_file_ext</title> <title>$tpl_file_ext</title>
<para> <para>
This is the extention used for template files. By default this This is the extention used for template files. By default this
@@ -301,7 +318,7 @@ chmod 700 cache
ignored. ignored.
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="setting.allow.php">
<title>$allow_php</title> <title>$allow_php</title>
<para> <para>
Whether or not to allow PHP code in the templates. If set to Whether or not to allow PHP code in the templates. If set to
@@ -312,26 +329,19 @@ chmod 700 cache
is "false". is "false".
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="setting.left.delimiter">
<title>$left_delimiter</title> <title>$left_delimiter</title>
<para> <para>
This is the left delimiter used by the template language. Default is "{". This is the left delimiter used by the template language. Default is "{".
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="setting.right.delimiter">
<title>$right_delimiter</title> <title>$right_delimiter</title>
<para> <para>
This is the right delimiter used by the template language. Default is "}". This is the right delimiter used by the template language. Default is "}".
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="setting.custom.funcs">
<title>$config_dir</title>
<para>
This is the directory used to store config files used in the templates.
Default is "configs".
</para>
</sect2>
<sect2>
<title>$custom_funcs</title> <title>$custom_funcs</title>
<para> <para>
This is a mapping of the names of <link 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. the names of functions in PHP. These are usually kept in Smarty.addons.php.
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="setting.custom.mods">
<title>$custom_mods</title> <title>$custom_mods</title>
<para> <para>
This is a mapping of the names of variable 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. the names of functions in PHP. These are usually kept in Smarty.addons.php.
</para> </para>
</sect2> </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> </sect1>
</chapter> </chapter>
<chapter> <chapter>
@@ -365,7 +366,7 @@ chmod 700 cache
</para> </para>
<sect1> <sect1>
<title>Smarty API Functions</title> <title>Smarty API Functions</title>
<sect2> <sect2 id="api.assign">
<title>assign</title> <title>assign</title>
<funcsynopsis> <funcsynopsis>
<funcprototype> <funcprototype>
@@ -385,7 +386,7 @@ chmod 700 cache
data gathered from database queries or other sources of data. data gathered from database queries or other sources of data.
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="api.append">
<title>append</title> <title>append</title>
<funcsynopsis> <funcsynopsis>
<funcprototype> <funcprototype>
@@ -404,7 +405,7 @@ chmod 700 cache
This is used to append data to existing variables in the template. This is used to append data to existing variables in the template.
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="api.clear.assign">
<title>clear_assign</title> <title>clear_assign</title>
<funcsynopsis> <funcsynopsis>
<funcprototype> <funcprototype>
@@ -416,7 +417,7 @@ chmod 700 cache
This clears the value of an assigned variable. This clears the value of an assigned variable.
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="api.clear.all.assign">
<title>clear_all_assign</title> <title>clear_all_assign</title>
<funcsynopsis> <funcsynopsis>
<funcprototype> <funcprototype>
@@ -428,6 +429,83 @@ chmod 700 cache
This clears the values of all assigned variables. This clears the values of all assigned variables.
</para> </para>
</sect2> </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"> <sect2 id="api.clear.all.cache">
<title>clear_all_cache</title> <title>clear_all_cache</title>
<funcsynopsis> <funcsynopsis>
@@ -451,12 +529,10 @@ chmod 700 cache
</funcsynopsis> </funcsynopsis>
<para> <para>
This returns true if there is a valid cache for this template. This returns true if there is a valid cache for this template.
Use this to skip process-intensive tasks that aren't necessary This was added to Smarty 1.3.0.
when a cached version of the template is available. This was
added to Smarty 1.3.0.
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="api.get.template.vars">
<title>get_template_vars</title> <title>get_template_vars</title>
<funcsynopsis> <funcsynopsis>
<funcprototype> <funcprototype>
@@ -468,20 +544,24 @@ chmod 700 cache
This gets an array of the currently assigned template vars. This gets an array of the currently assigned template vars.
</para> </para>
</sect2> </sect2>
<sect2> <sect2 id="api.display">
<title>display</title> <title>display</title>
<funcsynopsis> <funcsynopsis>
<funcprototype> <funcprototype>
<funcdef>void <function>display</function></funcdef> <funcdef>void <function>display</function></funcdef>
<paramdef>string <parameter>template</parameter></paramdef> <paramdef>string <parameter>template</parameter></paramdef>
<paramdef>string <parameter>cache id</parameter></paramdef>
</funcprototype> </funcprototype>
</funcsynopsis> </funcsynopsis>
<para> <para>
This displays the template. Supply a path relative to the 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> </para>
</sect2> </sect2>
<sect2> <sect2 id="api.fetch">
<title>fetch</title> <title>fetch</title>
<funcsynopsis> <funcsynopsis>
<funcprototype> <funcprototype>
@@ -491,13 +571,13 @@ chmod 700 cache
</funcsynopsis> </funcsynopsis>
<para> <para>
This returns the template output. Supply a path relative to the 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> </para>
</sect2> </sect2>
<sect2> <sect2>
<title>Using Smarty API</title> <title>Using Smarty API</title>
<example> <example>
<title>Example use of Smarty API</title> <title>Example use of Smarty API</title>
<programlisting> <programlisting>
include("Smarty.class.php"); include("Smarty.class.php");
@@ -528,7 +608,7 @@ $smarty->display("index.tpl");
// alternatively capture the output // alternatively capture the output
// $output = $smarty->fetch("index.tpl"); // $output = $smarty->fetch("index.tpl");
</programlisting> </programlisting>
</example> </example>
</sect2> </sect2>
</sect1> </sect1>
</chapter> </chapter>
@@ -943,12 +1023,12 @@ Intro = """This is a value that spans more
and display the returned results in place of the insert tag. and display the returned results in place of the insert tag.
</para> </para>
<para> <para>
A note on caching: If you have <link TECHNICAL NOTE: It is possible to have portions of the template not
linkend="setting.caching">caching</link> turned on, insert tags cached. If you have <link linkend="section.caching">caching</link>
will not be cached. They will run dynamically every time the page turned on, insert tags will not be cached. They will run
is created, even within cached pages. This works good for things dynamically every time the page is created, even within cached
like banners, polls, live weather, search results, user feedback pages. This works good for things like banners, polls, live
areas, etc. weather, search results, user feedback areas, etc.
</para> </para>
</sect2> </sect2>
<sect2> <sect2>
@@ -2502,26 +2582,28 @@ function makeTimeStamp($year="",$month="",$day="")
<chapter id="credits"> <chapter id="credits">
<title>CREDITS</title> <title>CREDITS</title>
<para> <para>
Monte Ohrt &lt;monte@ispi.net&gt;: Idea of compiling into PHP scripts, Monte Ohrt &lt;monte@ispi.net&gt;: Concepted compiling templates into PHP
initial implementation, documentation. scripts, wrote initial "proof of concept" implementation, and maintains
documentation.
</para> </para>
<para> <para>
Andrei Zmievski &lt;andrei@ispi.net&gt;: Rewrote parser from scratch, added Andrei Zmievski &lt;andrei@ispi.net&gt;: Rewrote parser from scratch and
custom modifier functionality, and much more. added other features too numerous to mention.
</para> </para>
<para> <para>
Anne Holz &lt;anne@ispi.net&gt;: Contributed several ideas for formatting features. Anne Holz &lt;anne@ispi.net&gt;: Many of Smarty's formatting features were
a direct result of needs from her department.
</para> </para>
<para> <para>
Frank Kromann &lt;fmk@php.net&gt;: Idea of custom function ability. Frank Kromann &lt;fmk@php.net&gt;: Idea of custom function ability.
</para> </para>
<para> <para>
A special thanks goes to all the people that have contributed other A special thanks goes to the people that have contributed other templating
templating solutions to the PHP community which we learned a lot from. solutions to the PHP community which we learned a lot from.
</para> </para>
<para> <para>
A special thanks goes to all the members of the php-template mailing list, A special thanks goes to the members of the php-template mailing list and
who shared and brought many ideas to the table. the smarty mailing list, whom shared and brought many ideas to the table.
</para> </para>
<para> <para>
Rasmus Lerdorf &lt;rasmus@php.net&gt;: For starting what eventually became Rasmus Lerdorf &lt;rasmus@php.net&gt;: For starting what eventually became

View File

@@ -4,8 +4,6 @@ require("Smarty.class.php");
$smarty = new Smarty; $smarty = new Smarty;
$smarty->caching = false;
$smarty->assign(now, time()); $smarty->assign(now, time());
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill"); $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'); $smarty->display('index.tpl');
function insert_foo($args)
{
extract($args);
return "test $arg1";
}
?> ?>

View File

@@ -46,9 +46,3 @@ testing strip tags
{/strip} {/strip}
</PRE> </PRE>
{insert name = foo
arg1=$now arg2=true}
test: {$now|date_format:"%I:%M %p"}