Tidy up of formatting

This commit is contained in:
pete_morgan
2006-09-27 01:47:51 +00:00
parent 7a82d2caf9
commit e521084a10
6 changed files with 183 additions and 131 deletions

View File

@@ -5,15 +5,24 @@
<para> <para>
Smarty allows access to PHP Smarty allows access to PHP
<ulink url="&url.php-manual;object">objects</ulink> through the templates. <ulink url="&url.php-manual;object">objects</ulink> through the templates.
There are There are two ways to access them.
two ways to access them. One way is to </para>
<link linkend="api.register.object">register objects</link> to the template,
then use access them via syntax similar to <itemizedlist spacing="compact">
<link linkend="language.custom.functions">custom functions</link>. <listitem><para>
The other way One way is to <link linkend="api.register.object">register objects</link> to
is to <link linkend="api.assign">assign()</link> objects the template, then use access them via syntax similar to
to the templates and access them much like any other <link linkend="language.custom.functions">custom functions</link>.
assigned variable. The first method has a much nicer template syntax. It </para></listitem>
<listitem><para>
The other way is to <link linkend="api.assign"><varname>assign()</varname>
</link> objects to the templates and access them much like any other
assigned variable.
</para></listitem>
</itemizedlist>
<para>
The first method has a much nicer template syntax. It
is also more secure, as a registered object can be restricted to certain is also more secure, as a registered object can be restricted to certain
methods or properties. However, methods or properties. However,
<emphasis role="bold">a registered object cannot be looped over <emphasis role="bold">a registered object cannot be looped over
@@ -22,9 +31,9 @@
keep template syntax to a minimum. keep template syntax to a minimum.
</para> </para>
<para> <para>
If <link linkend="variable.security">$security</link> is enabled, If <link linkend="variable.security"><parameter>$security</parameter></link>
no private methods or functions can be accessed is enabled, no private methods or functions can be accessed
(begininning with "_"). If a method and property of the same name exist, (begininning with '_'). If a method and property of the same name exist,
the method will be used. the method will be used.
</para> </para>
<para> <para>
@@ -38,19 +47,20 @@
An associative array is passed An associative array is passed
as the first parameter, and the smarty object as the second. If you want 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 the parameters passed one at a time for each argument like traditional
object parameter passing, set the fourth registration parameter to false. object parameter passing, set the fourth registration parameter to &false;.
</para> </para>
<para> <para>
The optional fifth parameter has only effect with The optional fifth parameter has only effect with
<parameter>format</parameter> being <literal>true</literal> <parameter>format</parameter> being &true;
and contains a list of methods that should be treated as and contains a list of methods that should be treated as
blocks. That means these methods have a closing tag in the blocks. That means these methods have a closing tag in the
template template
(<literal>{foobar->meth2}...{/foobar->meth2}</literal>) and (<literal>{foobar->meth2}...{/foobar->meth2}</literal>) and
the parameters to the methods have the same synopsis as the the parameters to the methods have the same synopsis as the
parameters for parameters for
<link linkend="plugins.block.functions">block-function-plugins</link>: <link linkend="plugins.block.functions">
They get 4 parameters <varname>block-function-plugins</varname></link>:
They get the four parameters
<parameter>$params</parameter>, <parameter>$params</parameter>,
<parameter>$content</parameter>, <parameter>$content</parameter>,
<parameter>&amp;$smarty</parameter> and <parameter>&amp;$smarty</parameter> and
@@ -58,7 +68,7 @@
block-function-plugins. block-function-plugins.
</para> </para>
<example> <example>
<title>using a registered or assigned object</title> <title>Using a registered or assigned object</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
@@ -71,14 +81,17 @@ class My_Object {
} }
$myobj = new My_Object; $myobj = new My_Object;
// registering the object (will be by reference) // registering the object (will be by reference)
$smarty->register_object('foobar',$myobj); $smarty->register_object('foobar',$myobj);
// if we want to restrict access to certain methods or properties, list them // if we want to restrict access to certain methods or properties, list them
$smarty->register_object('foobar',$myobj,array('meth1','meth2','prop1')); $smarty->register_object('foobar',$myobj,array('meth1','meth2','prop1'));
// if you want to use the traditional object parameter format, pass a boolean of false // if you want to use the traditional object parameter format, pass a boolean of false
$smarty->register_object('foobar',$myobj,null,false); $smarty->register_object('foobar',$myobj,null,false);
// We can also assign objects. Assign by ref when possible. // We can also assign objects. assign_by_ref when possible.
$smarty->assign_by_ref('myobj', $myobj); $smarty->assign_by_ref('myobj', $myobj);
$smarty->display('index.tpl'); $smarty->display('index.tpl');
@@ -86,7 +99,7 @@ $smarty->display('index.tpl');
]]> ]]>
</programlisting> </programlisting>
<para> <para>
And here's how to access your objects in index.tpl: And here's how to access your objects in <filename>index.tpl</filename>:
</para> </para>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
@@ -104,8 +117,9 @@ the output was {$output}
</example> </example>
<para> <para>
See also <link See also <link
linkend="api.register.object">register_object()</link> and <link linkend="api.register.object"><varname>register_object()</varname></link>
linkend="api.assign">assign()</link> and
<link linkend="api.assign"><varname>assign()</varname></link>.
</para> </para>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file

View File

@@ -4,10 +4,11 @@
<title>Output Filters</title> <title>Output Filters</title>
<para> <para>
When the template is invoked via When the template is invoked via
<link linkend="api.display">display()</link> or <link linkend="api.display"><varname>display()</varname></link> or
<link linkend="api.fetch">fetch()</link>, its output can be <link linkend="api.fetch"><varname>fetch()</varname></link>, its output can
sent through one or more output filters. This differs from be sent through one or more output filters. This differs from
<link linkend="advanced.features.postfilters">postfilters</link> <link linkend="advanced.features.postfilters">
<varname>postfilters</varname></link>
because postfilters operate on compiled templates before they are saved to because postfilters operate on compiled templates before they are saved to
the disk, whereas output filters operate on the template output when it is the disk, whereas output filters operate on the template output when it is
executed. executed.
@@ -18,14 +19,14 @@
<link linkend="api.register.outputfilter">registered</link> or loaded <link linkend="api.register.outputfilter">registered</link> or loaded
from the from the
<link linkend="variable.plugins.dir">plugins directory</link> by using the <link linkend="variable.plugins.dir">plugins directory</link> by using the
<link linkend="api.load.filter">load_filter()</link> function or by <link linkend="api.load.filter"><varname>load_filter()</varname></link>
setting the method or by setting the <link linkend="variable.autoload.filters">
<link linkend="variable.autoload.filters">$autoload_filters</link> <parameter>$autoload_filters</parameter></link> variable.
variable. Smarty will pass the template output as the first argument, Smarty will pass the template output as the first argument,
and expect the function to return the result of the processing. and expect the function to return the result of the processing.
</para> </para>
<example> <example>
<title>using a template outputfilter</title> <title>Using a template outputfilter</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
@@ -50,11 +51,11 @@ $smarty->display('index.tpl');
</example> </example>
<para> <para>
See also See also
<link linkend="api.register.outputfilter">register_outpurfilter()</link>, <link linkend="api.register.outputfilter"><varname>register_outpurfilter()</varname></link>,
<link linkend="api.load.filter">load_filter()</link>, <link linkend="api.load.filter"><varname>load_filter()</varname></link>,
<link linkend="variable.autoload.filters">$autoload_filters</link>, <link linkend="variable.autoload.filters"><parameter>$autoload_filters</parameter></link>,
<link linkend="advanced.features.postfilters">postfilters</link> and <link linkend="advanced.features.postfilters">postfilters</link> and
<link linkend="variable.plugins.dir">$plugins_dir</link>. <link linkend="variable.plugins.dir"><parameter>$plugins_dir</parameter></link>.
</para> </para>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file

View File

@@ -4,19 +4,19 @@
<title>Postfilters</title> <title>Postfilters</title>
<para> <para>
Template postfilters are PHP functions that your templates are ran through Template postfilters are PHP functions that your templates are ran through
after they are compiled. Postfilters can be either <emphasis>after they are compiled</emphasis>. Postfilters can be either
<link linkend="api.register.postfilter">registered</link> or loaded <link linkend="api.register.postfilter">registered</link> or loaded
from the <link linkend="variable.plugins.dir">plugins directory</link> from the <link linkend="variable.plugins.dir">plugins directory</link>
by using the by using the
<link linkend="api.load.filter">load_filter()</link> function or by <link linkend="api.load.filter"><varname>load_filter()</varname></link>
setting the function or by setting the <link linkend="variable.autoload.filters">
<link linkend="variable.autoload.filters">$autoload_filters</link> <parameter>$autoload_filters</parameter></link> variable.
variable. Smarty will pass the compiled template code as the first Smarty will pass the compiled template code as the first
argument, and expect the function to return the result of the argument, and expect the function to return the result of the
processing. processing.
</para> </para>
<example> <example>
<title>using a template postfilter</title> <title>Using a template postfilter</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
@@ -33,7 +33,8 @@ $smarty->display('index.tpl');
]]> ]]>
</programlisting> </programlisting>
<para> <para>
This will make the compiled Smarty template index.tpl look like: The postfilter above will make the compiled Smarty template
<filename>index.tpl</filename> look like:
</para> </para>
<screen> <screen>
<![CDATA[ <![CDATA[
@@ -43,10 +44,11 @@ $smarty->display('index.tpl');
</screen> </screen>
</example> </example>
<para> <para>
See also <link linkend="api.register.postfilter">register_postfilter()</link>, See also
<link linkend="api.register.postfilter"><varname>register_postfilter()</varname></link>,
<link linkend="advanced.features.prefilters">prefilters</link> <link linkend="advanced.features.prefilters">prefilters</link>
and and
<link linkend="api.load.filter">load_filter()</link>. <link linkend="api.load.filter"><varname>load_filter()</varname></link>.
</para> </para>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file

View File

@@ -4,27 +4,27 @@
<title>Prefilters</title> <title>Prefilters</title>
<para> <para>
Template prefilters are PHP functions that your templates are ran through Template prefilters are PHP functions that your templates are ran through
before they are compiled. This is good for preprocessing your templates <emphasis>before they are compiled</emphasis>. This is good for preprocessing
to remove unwanted comments, keeping an eye on what people are putting your templates to remove unwanted comments, keeping an eye on what people are
in their templates, etc. putting in their templates, etc.
</para> </para>
<para> <para>
Prefilters can be either <link Prefilters can be either <link
linkend="api.register.prefilter">registered</link> or loaded from linkend="api.register.prefilter">registered</link> or loaded from
the <link linkend="variable.plugins.dir">plugins directory</link> the <link linkend="variable.plugins.dir">plugins directory</link>
by using <link by using <link
linkend="api.load.filter">load_filter()</link> function or by setting linkend="api.load.filter"><varname>load_filter()</varname></link> function or
the <link linkend="variable.autoload.filters">$autoload_filters</link> by setting the <link linkend="variable.autoload.filters">
variable. <parameter>$autoload_filters</parameter></link> variable.
</para> </para>
<para> <para>
Smarty will pass the template source code as the first argument, and Smarty will pass the template source code as the first argument, and
expect the function to return the resulting template source code. expect the function to return the resulting template source code.
</para> </para>
<example> <example>
<title>using a template prefilter</title> <title>Using a template prefilter</title>
<para> <para>
This will remove all the comments in the template source. This will remove all the html comments in the template source.
</para> </para>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
@@ -43,10 +43,11 @@ $smarty->display('index.tpl');
</programlisting> </programlisting>
</example> </example>
<para>See also <link linkend="api.register.prefilter">register_prefilter()</link>, <para>See also
<link linkend="api.register.prefilter"><varname>register_prefilter()</varname></link>,
<link linkend="advanced.features.postfilters">postfilters</link> <link linkend="advanced.features.postfilters">postfilters</link>
and and
<link linkend="api.load.filter">load_filter()</link>. <link linkend="api.load.filter"><varname>load_filter()</varname></link>.
</para> </para>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file

View File

@@ -4,34 +4,64 @@
<title>Cache Handler Function</title> <title>Cache Handler Function</title>
<para> <para>
As an alternative to using the default file-based caching mechanism, you As an alternative to using the default file-based caching mechanism, you
can specify a custom cache handling function that will be used to read, can specify a custom cache handling function that will be used to
write and clear cached files. <literal>read</literal>, <literal>write</literal> and
<literal>clear</literal> cached files.
</para> </para>
<para> <para>
Create a function in your application that Smarty will use as a Create a function in your application that Smarty will use as a
cache handler. Set the name of it in the cache handler. Set the name of it in the
<link linkend="variable.cache.handler.func">$cache_handler_func</link> <link linkend="variable.cache.handler.func">
class variable. Smarty will now use this to handle cached data. The <parameter>$cache_handler_func</parameter></link>
first argument is the action, which will be one of 'read', 'write' and class variable. Smarty will now use this to handle cached data.
'clear'. The second parameter is the Smarty object. The third parameter </para>
is the cached content. Upon a write, Smarty passes the cached content
in these parameters. Upon a 'read', Smarty expects your function to <itemizedlist>
accept this parameter by reference and populate it with the cached <listitem><para>
data. Upon a 'clear', pass a dummy variable here since it is not used. The first argument is the action, which will be one of
The fourth parameter is the name of the template file (needed for <literal>read</literal>, <literal>write</literal> and
read/write), the fifth parameter is the cache_id (optional), and the <literal>clear</literal>.
sixth is the compile_id (optional). </para></listitem>
</para>
<para> <listitem><para>
Note: The last parameter ($exp_time) was added in Smarty-2.6.0. The second parameter is the Smarty object.
</para> </para></listitem>
<listitem><para>The third parameter
is the cached content. Upon a <literal>write</literal>, Smarty passes the
cached content in these parameters. Upon a <literal>read</literal>,
Smarty expects your function to accept this parameter by reference and
populate it with the cached data. Upon a <literal>clear</literal>, pass a
dummy variable here since it is not used.
</para></listitem>
<listitem><para>
The fourth parameter is the <parameter>name</parameter> of the template
file, needed for read/write.
</para></listitem>
<listitem><para>
The fifth parameter is the optional <parameter>$cache_id</parameter>.
</para></listitem>
<listitem><para>
The sixth is the optional <link linkend="variable.compile.id">
<parameter>$compile_id</parameter></link>.
</para></listitem>
<listitem><para>
The seventh and last parameter <parameter>$exp_time</parameter>
was added in Smarty-2.6.0.
</para></listitem>
</itemizedlist>
<example> <example>
<title>example using MySQL as a cache source</title> <title>Example using MySQL as a cache source</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
/* /**************************************************
example usage: example usage:
include('Smarty.class.php'); include('Smarty.class.php');
@@ -52,7 +82,7 @@ CacheID char(32) PRIMARY KEY,
CacheContents MEDIUMTEXT NOT NULL CacheContents MEDIUMTEXT NOT NULL
); );
*/ **************************************************/
function mysql_cache_handler($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null, $exp_time=null) function mysql_cache_handler($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null, $exp_time=null)
{ {

View File

@@ -4,37 +4,42 @@
<title>Resources</title> <title>Resources</title>
<para> <para>
The templates may come from a variety of sources. When you The templates may come from a variety of sources. When you
<link linkend="api.display">display()</link> or <link linkend="api.display"><varname>display()</varname></link> or
<link linkend="api.fetch">fetch()</link> <link linkend="api.fetch"><varname>fetch()</varname></link>
a template, or when you include a template from within another template, a template, or when you include a template from within another template,
you supply a resource type, followed by the appropriate path and template you supply a resource type, followed by the appropriate path and template
name. If a resource is not explicitly given the value of <link name. If a resource is not explicitly given the value of <link
linkend="variable.default.resource.type">$default_resource_type</link> is linkend="variable.default.resource.type">
assumed. <parameter>$default_resource_type</parameter></link> is assumed.
</para> </para>
<sect2 id="templates.from.template.dir"> <sect2 id="templates.from.template.dir">
<title>Templates from $template_dir</title> <title>Templates from $template_dir</title>
<para> <para>
Templates from the Templates from the <link linkend="variable.template.dir">
<link linkend="variable.template.dir">$template_dir</link> do not require a template <parameter>$template_dir</parameter></link> do not require a template
resource, although you can use the file: resource for consistancy. resource, although you can use the <literal>file:</literal> resource
Just supply the path to the template you want to use relative to the for consistancy. Just supply the path to the template you want to use
<link linkend="variable.template.dir">$template_dir</link> relative to the <link linkend="variable.template.dir">
root directory. <parameter>$template_dir</parameter></link> root directory.
</para> </para>
<example> <example>
<title>using templates from $template_dir</title> <title>Using templates from the $template_dir</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
$smarty->display("index.tpl"); $smarty->display('index.tpl');
$smarty->display("admin/menu.tpl"); $smarty->display('admin/menu.tpl');
$smarty->display("file:admin/menu.tpl"); // same as one above $smarty->display('file:admin/menu.tpl'); // same as one above
?> ?>
]]>
{* from within Smarty template *} </programlisting>
{include file="index.tpl"} <para>From within a Smarty template</para>
{include file="file:index.tpl"} {* same as one above *} <programlisting>
<![CDATA[
{include file='index.tpl'}
{* below is same as above *}
{include file='file:index.tpl'}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
@@ -42,28 +47,27 @@ $smarty->display("file:admin/menu.tpl"); // same as one above
<sect2 id="templates.from.any.dir"> <sect2 id="templates.from.any.dir">
<title>Templates from any directory</title> <title>Templates from any directory</title>
<para> <para>
Templates outside of the Templates outside of the <link linkend="variable.template.dir">
<link linkend="variable.template.dir">$template_dir</link> <parameter>$template_dir</parameter></link>
require the file: template require the <literal>file:</literal> template resource type, followed by
resource type, followed by the absolute path and name of the the absolute path to the template.
template.
</para> </para>
<example> <example>
<title>using templates from any directory</title> <title>Using templates from any directory</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
$smarty->display("file:/export/templates/index.tpl"); $smarty->display('file:/export/templates/index.tpl');
$smarty->display("file:/path/to/my/templates/menu.tpl"); $smarty->display('file:/path/to/my/templates/menu.tpl');
?> ?>
]]> ]]>
</programlisting> </programlisting>
<para> <para>
And from within Smarty template: And from within a Smarty template:
</para> </para>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{include file="file:/usr/local/share/templates/navigation.tpl"} {include file='file:/usr/local/share/templates/navigation.tpl'}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
@@ -73,16 +77,16 @@ $smarty->display("file:/path/to/my/templates/menu.tpl");
<para> <para>
If you are using a Windows machine, filepaths usually include a If you are using a Windows machine, filepaths usually include a
drive letter (C:) at the beginning of the pathname. Be sure to use drive letter (C:) at the beginning of the pathname. Be sure to use
"file:" in the path to avoid namespace conflicts and get the <literal>file:</literal> in the path to avoid namespace conflicts and
desired results. get the desired results.
</para> </para>
<example> <example>
<title>using templates from windows file paths</title> <title>Using templates from windows file paths</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
$smarty->display("file:C:/export/templates/index.tpl"); $smarty->display('file:C:/export/templates/index.tpl');
$smarty->display("file:F:/path/to/my/templates/menu.tpl"); $smarty->display('file:F:/path/to/my/templates/menu.tpl');
?> ?>
]]> ]]>
</programlisting> </programlisting>
@@ -91,7 +95,7 @@ $smarty->display("file:F:/path/to/my/templates/menu.tpl");
</para> </para>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{include file="file:D:/usr/local/share/templates/navigation.tpl"} {include file='file:D:/usr/local/share/templates/navigation.tpl'}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
@@ -116,13 +120,13 @@ $smarty->display("file:F:/path/to/my/templates/menu.tpl");
<note> <note>
<para> <para>
Note that you cannot override the built-in Note that you cannot override the built-in
<literal>file</literal> resource, but you can provide a resource <literal>file:</literal> resource, but you can provide a resource
that fetches templates from the file system in some other way by that fetches templates from the file system in some other way by
registering under another resource name. registering under another resource name.
</para> </para>
</note> </note>
<example> <example>
<title>using custom resources</title> <title>Using custom resources</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
@@ -185,7 +189,7 @@ $smarty->display("db:index.tpl");
</para> </para>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{include file="db:/extras/navigation.tpl"} {include file='db:/extras/navigation.tpl'}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
@@ -200,7 +204,7 @@ $smarty->display("db:index.tpl");
on-the-fly. on-the-fly.
</para> </para>
<example> <example>
<title>using the default template handler function</title> <title>Using the default template handler function</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php