* some wz

* no tab
* add Cdata section
This commit is contained in:
yannick
2005-05-10 20:54:42 +00:00
parent aeab0151bf
commit 9d92dc1613
6 changed files with 412 additions and 383 deletions

View File

@@ -1,87 +1,87 @@
<?xml version="1.0" encoding="iso-8859-1"?> <?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ --> <!-- $Revision$ -->
<sect1 id="language.function.capture"> <sect1 id="language.function.capture">
<title>capture</title> <title>capture</title>
<informaltable frame="all"> <informaltable frame="all">
<tgroup cols="5"> <tgroup cols="5">
<colspec colname="param" align="center" /> <colspec colname="param" align="center" />
<colspec colname="type" align="center" /> <colspec colname="type" align="center" />
<colspec colname="required" align="center" /> <colspec colname="required" align="center" />
<colspec colname="default" align="center" /> <colspec colname="default" align="center" />
<colspec colname="desc" /> <colspec colname="desc" />
<thead> <thead>
<row> <row>
<entry>Attribute Name</entry> <entry>Attribute Name</entry>
<entry>Type</entry> <entry>Type</entry>
<entry>Required</entry> <entry>Required</entry>
<entry>Default</entry> <entry>Default</entry>
<entry>Description</entry> <entry>Description</entry>
</row> </row>
</thead> </thead>
<tbody> <tbody>
<row> <row>
<entry>name</entry> <entry>name</entry>
<entry>string</entry> <entry>string</entry>
<entry>no</entry> <entry>no</entry>
<entry><emphasis>default</emphasis></entry> <entry><emphasis>default</emphasis></entry>
<entry>The name of the captured block</entry> <entry>The name of the captured block</entry>
</row> </row>
<row> <row>
<entry>assign</entry> <entry>assign</entry>
<entry>string</entry> <entry>string</entry>
<entry>No</entry> <entry>No</entry>
<entry><emphasis>n/a</emphasis></entry> <entry><emphasis>n/a</emphasis></entry>
<entry>The variable name where to assign the captured output to</entry> <entry>The variable name where to assign the captured output to</entry>
</row> </row>
</tbody> </tbody>
</tgroup> </tgroup>
</informaltable> </informaltable>
<para> <para>
capture is used to collect the output of the template into a capture is used to collect the output of the template into a
variable instead of displaying it. Any content between {capture variable instead of displaying it. Any content between {capture
name="foo"} and {/capture} is collected into the variable specified name="foo"} and {/capture} is collected into the variable specified
in the name attribute. The captured content can be used in the in the name attribute. The captured content can be used in the
template from the special variable $smarty.capture.foo where foo is template from the special variable $smarty.capture.foo where foo is
the value passed in the name attribute. If you do not supply a name the value passed in the name attribute. If you do not supply a name
attribute, then "default" will be used. All {capture} commands must attribute, then "default" will be used. All {capture} commands must
be paired with {/capture}. You can nest capture commands. be paired with {/capture}. You can nest capture commands.
</para> </para>
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
Smarty 1.4.0 - 1.4.4 placed the captured content into the Smarty 1.4.0 - 1.4.4 placed the captured content into the
variable named $return. As of 1.4.5, this behavior was changed to use variable named $return. As of 1.4.5, this behavior was changed to use
the name attribute, so update your templates accordingly. the name attribute, so update your templates accordingly.
</para> </para>
</note> </note>
<caution> <caution>
<para> <para>
Be careful when capturing <command>insert</command> output. If Be careful when capturing <command>insert</command> output. If
you have caching turned on and you have <command>insert</command> you have caching turned on and you have <command>insert</command>
commands that you expect to run within cached content, do not commands that you expect to run within cached content, do not
capture this content. capture this content.
</para> </para>
</caution> </caution>
<para> <para>
<example> <example>
<title>capturing template content</title> <title>capturing template content</title>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{* we don't want to print a table row unless content is displayed *} {* we don't want to print a table row unless content is displayed *}
{capture name=banner} {capture name=banner}
{include file="get_banner.tpl"} {include file="get_banner.tpl"}
{/capture} {/capture}
{if $smarty.capture.banner ne ""} {if $smarty.capture.banner ne ""}
<tr> <tr>
<td> <td>
{$smarty.capture.banner} {$smarty.capture.banner}
</td> </td>
</tr> </tr>
{/if} {/if}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
</para> </para>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
Local variables: Local variables:

View File

@@ -1,107 +1,122 @@
<?xml version="1.0" encoding="iso-8859-1"?> <?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ --> <!-- $Revision$ -->
<sect1 id="language.function.include"> <sect1 id="language.function.include">
<title>include</title> <title>include</title>
<informaltable frame="all"> <informaltable frame="all">
<tgroup cols="5"> <tgroup cols="5">
<colspec colname="param" align="center" /> <colspec colname="param" align="center" />
<colspec colname="type" align="center" /> <colspec colname="type" align="center" />
<colspec colname="required" align="center" /> <colspec colname="required" align="center" />
<colspec colname="default" align="center" /> <colspec colname="default" align="center" />
<colspec colname="desc" /> <colspec colname="desc" />
<thead> <thead>
<row> <row>
<entry>Attribute Name</entry> <entry>Attribute Name</entry>
<entry>Type</entry> <entry>Type</entry>
<entry>Required</entry> <entry>Required</entry>
<entry>Default</entry> <entry>Default</entry>
<entry>Description</entry> <entry>Description</entry>
</row> </row>
</thead> </thead>
<tbody> <tbody>
<row> <row>
<entry>file</entry> <entry>file</entry>
<entry>string</entry> <entry>string</entry>
<entry>Yes</entry> <entry>Yes</entry>
<entry><emphasis>n/a</emphasis></entry> <entry><emphasis>n/a</emphasis></entry>
<entry>The name of the template file to include</entry> <entry>The name of the template file to include</entry>
</row> </row>
<row> <row>
<entry>assign</entry> <entry>assign</entry>
<entry>string</entry> <entry>string</entry>
<entry>No</entry> <entry>No</entry>
<entry><emphasis>n/a</emphasis></entry> <entry><emphasis>n/a</emphasis></entry>
<entry>The name of the variable that the output of <entry>The name of the variable that the output of
include will be assigned to</entry> include will be assigned to</entry>
</row> </row>
<row> <row>
<entry>[var ...]</entry> <entry>[var ...]</entry>
<entry>[var type]</entry> <entry>[var type]</entry>
<entry>No</entry> <entry>No</entry>
<entry><emphasis>n/a</emphasis></entry> <entry><emphasis>n/a</emphasis></entry>
<entry>variable to pass local to template</entry> <entry>variable to pass local to template</entry>
</row> </row>
</tbody> </tbody>
</tgroup> </tgroup>
</informaltable> </informaltable>
<para> <para>
Include tags are used for including other templates in the current Include tags are used for including other templates in the current
template. Any variables available in the current template are also template. Any variables available in the current template are also
available within the included template. The include tag must have available within the included template. The include tag must have
the attribute "file", which contains the template resource path. the attribute "file", which contains the template resource path.
</para> </para>
<para> <para>
You can optionally pass the <emphasis>assign</emphasis> attribute, You can optionally pass the <emphasis>assign</emphasis> attribute,
which will specify a template variable name that the output of which will specify a template variable name that the output of
<emphasis>include</emphasis> will be assigned to instead of <emphasis>include</emphasis> will be assigned to instead of
displayed. displayed.
</para> </para>
<example> <example>
<title>function include</title> <title>function include</title>
<programlisting> <programlisting>
{include file="header.tpl"} <![CDATA[
{include file="header.tpl"}
{* body of template goes here *} {* body of template goes here *}
{include file="footer.tpl"}</programlisting> {include file="footer.tpl"}
</example> ]]>
<para> </programlisting>
You can also pass variables to included templates as attributes. </example>
Any variables explicitly passed to an included template as <para>
attributes are only available within the scope of the included You can also pass variables to included templates as attributes.
file. Attribute variables override current template variables, in Any variables explicitly passed to an included template as
the case they are named alike. attributes are only available within the scope of the included
</para> file. Attribute variables override current template variables, in
<example> the case they are named alike.
<title>function include passing variables</title> </para>
<programlisting> <example>
{include file="header.tpl" title="Main Menu" table_bgcolor="#c0c0c0"} <title>function include passing variables</title>
<programlisting>
<![CDATA[
{include file="header.tpl" title="Main Menu" table_bgcolor="#c0c0c0"}
{* body of template goes here *} {* body of template goes here *}
{include file="footer.tpl" logo="http://my.example.com/logo.gif"}</programlisting> {include file="footer.tpl" logo="http://my.example.com/logo.gif"}
</example> ]]>
<para> </programlisting>
Use the syntax for <link </example>
linkend="template.resources">template resources</link> to <para>
include files outside of the <link linkend="variable.template.dir">$template_dir</link> directory. Use the syntax for <link
</para> linkend="template.resources">template resources</link> to
<example> include files outside of the <link linkend="variable.template.dir">$template_dir</link> directory.
<title>function include template resource examples</title> </para>
<programlisting> <example>
{* absolute filepath *} <title>function include template resource examples</title>
{include file="/usr/local/include/templates/header.tpl"} <programlisting>
<![CDATA[
{* absolute filepath *}
{include file="/usr/local/include/templates/header.tpl"}
{* absolute filepath (same thing) *} {* absolute filepath (same thing) *}
{include file="file:/usr/local/include/templates/header.tpl"} {include file="file:/usr/local/include/templates/header.tpl"}
{* windows absolute filepath (MUST use "file:" prefix) *} {* windows absolute filepath (MUST use "file:" prefix) *}
{include file="file:C:/www/pub/templates/header.tpl"} {include file="file:C:/www/pub/templates/header.tpl"}
{* include from template resource named "db" *} {* include from template resource named "db" *}
{include file="db:header.tpl"}</programlisting> {include file="db:header.tpl"}
</example> ]]>
<para>See also <link linkend="language.function.include.php">{include_php}</link>, <link linkend="language.function.php">{php}</link> <link linkend="template.resources">Template Resources</link> and <link linkend="tips.componentized.templates">Componentized Templates</link></para> </programlisting>
</example>
<para>
See also
<link linkend="language.function.include.php">{include_php}</link>,
<link linkend="language.function.php">{php}</link>,
<link linkend="template.resources">Template Resources</link> and
<link linkend="tips.componentized.templates">Componentized Templates</link>.
</para>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
Local variables: Local variables:

View File

@@ -1,124 +1,124 @@
<?xml version="1.0" encoding="iso-8859-1"?> <?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ --> <!-- $Revision$ -->
<sect1 id="language.function.insert"> <sect1 id="language.function.insert">
<title>insert</title> <title>insert</title>
<informaltable frame="all"> <informaltable frame="all">
<tgroup cols="5"> <tgroup cols="5">
<colspec colname="param" align="center" /> <colspec colname="param" align="center" />
<colspec colname="type" align="center" /> <colspec colname="type" align="center" />
<colspec colname="required" align="center" /> <colspec colname="required" align="center" />
<colspec colname="default" align="center" /> <colspec colname="default" align="center" />
<colspec colname="desc" /> <colspec colname="desc" />
<thead> <thead>
<row> <row>
<entry>Attribute Name</entry> <entry>Attribute Name</entry>
<entry>Type</entry> <entry>Type</entry>
<entry>Required</entry> <entry>Required</entry>
<entry>Default</entry> <entry>Default</entry>
<entry>Description</entry> <entry>Description</entry>
</row> </row>
</thead> </thead>
<tbody> <tbody>
<row> <row>
<entry>name</entry> <entry>name</entry>
<entry>string</entry> <entry>string</entry>
<entry>Yes</entry> <entry>Yes</entry>
<entry><emphasis>n/a</emphasis></entry> <entry><emphasis>n/a</emphasis></entry>
<entry>The name of the insert function (insert_name)</entry> <entry>The name of the insert function (insert_name)</entry>
</row> </row>
<row> <row>
<entry>assign</entry> <entry>assign</entry>
<entry>string</entry> <entry>string</entry>
<entry>No</entry> <entry>No</entry>
<entry><emphasis>n/a</emphasis></entry> <entry><emphasis>n/a</emphasis></entry>
<entry>The name of the template variable the output will <entry>The name of the template variable the output will
be assigned to</entry> be assigned to</entry>
</row> </row>
<row> <row>
<entry>script</entry> <entry>script</entry>
<entry>string</entry> <entry>string</entry>
<entry>No</entry> <entry>No</entry>
<entry><emphasis>n/a</emphasis></entry> <entry><emphasis>n/a</emphasis></entry>
<entry>The name of the php script that is included before <entry>The name of the php script that is included before
the insert function is called</entry> the insert function is called</entry>
</row> </row>
<row> <row>
<entry>[var ...]</entry> <entry>[var ...]</entry>
<entry>[var type]</entry> <entry>[var type]</entry>
<entry>No</entry> <entry>No</entry>
<entry><emphasis>n/a</emphasis></entry> <entry><emphasis>n/a</emphasis></entry>
<entry>variable to pass to insert function</entry> <entry>variable to pass to insert function</entry>
</row> </row>
</tbody> </tbody>
</tgroup> </tgroup>
</informaltable> </informaltable>
<para> <para>
Insert tags work much like include tags, except that insert tags Insert tags work much like include tags, except that insert tags
are not cached when you have template <link are not cached when you have template <link
linkend="caching">caching</link> enabled. They will be linkend="caching">caching</link> enabled. They will be
executed on every invocation of the template. executed on every invocation of the template.
</para> </para>
<para> <para>
Let's say you have a template with a banner slot at the top of Let's say you have a template with a banner slot at the top of
the page. The banner can contain any mixture of HTML, images, the page. The banner can contain any mixture of HTML, images,
flash, etc. so we can't just use a static link here, and we flash, etc. so we can't just use a static link here, and we
don't want this contents cached with the page. In comes the don't want this contents cached with the page. In comes the
insert tag: the template knows #banner_location_id# and insert tag: the template knows #banner_location_id# and
#site_id# values (gathered from a config file), and needs to #site_id# values (gathered from a config file), and needs to
call a function to get the banner contents. call a function to get the banner contents.
</para> </para>
<example> <example>
<title>function insert</title> <title>function insert</title>
<programlisting> <programlisting>
{* example of fetching a banner *} {* example of fetching a banner *}
{insert name="getBanner" lid=#banner_location_id# sid=#site_id#}</programlisting> {insert name="getBanner" lid=#banner_location_id# sid=#site_id#}</programlisting>
</example> </example>
<para> <para>
In this example, we are using the name "getBanner" and passing the In this example, we are using the name "getBanner" and passing the
parameters #banner_location_id# and #site_id#. Smarty will look parameters #banner_location_id# and #site_id#. Smarty will look
for a function named insert_getBanner() in your PHP application, passing for a function named insert_getBanner() in your PHP application, passing
the values of #banner_location_id# and #site_id# as the first argument the values of #banner_location_id# and #site_id# as the first argument
in an associative array. All insert function names in in an associative array. All insert function names in
your application must be prepended with "insert_" to remedy possible your application must be prepended with "insert_" to remedy possible
function name-space conflicts. Your insert_getBanner() function should function name-space conflicts. Your insert_getBanner() function should
do something with the passed values and return the results. These results do something with the passed values and return the results. These results
are then displayed in the template in place of the insert tag. are then displayed in the template in place of the insert tag.
In this example, Smarty would call this function: In this example, Smarty would call this function:
insert_getBanner(array("lid" => "12345","sid" => "67890")); insert_getBanner(array("lid" => "12345","sid" => "67890"));
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>
If you supply the "assign" attribute, the output of the insert tag If you supply the "assign" attribute, the output of the insert tag
will be assigned to this template variable instead of being output will be assigned to this template variable instead of being output
to the template. NOTE: assigning the output to a template variable to the template. NOTE: assigning the output to a template variable
isn't too useful with caching enabled. isn't too useful with caching enabled.
</para> </para>
<para> <para>
If you supply the "script" attribute, this php script will be If you supply the "script" attribute, this php script will be
included (only once) before the insert function is executed. This included (only once) before the insert function is executed. This
is the case where the insert function may not exist yet, and a php is the case where the insert function may not exist yet, and a php
script must be included first to make it work. The path can be script must be included first to make it work. The path can be
either absolute, or relative to $trusted_dir. When security is either absolute, or relative to $trusted_dir. When security is
enabled, the script must reside in $trusted_dir. enabled, the script must reside in $trusted_dir.
</para> </para>
<para> <para>
The Smarty object is passed as the second argument. This way you The Smarty object is passed as the second argument. This way you
can reference and modify information in the Smarty object from can reference and modify information in the Smarty object from
within the insert function. within the insert function.
</para> </para>
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
It is possible to have portions of the template not It is possible to have portions of the template not
cached. If you have <link linkend="caching">caching</link> cached. If you have <link linkend="caching">caching</link>
turned on, insert tags will not be cached. They will run turned on, insert tags will not be cached. They will run
dynamically every time the page is created, even within cached dynamically every time the page is created, even within cached
pages. This works good for things like banners, polls, live pages. This works good for things like banners, polls, live
weather, search results, user feedback areas, etc. weather, search results, user feedback areas, etc.
</para> </para>
</note> </note>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
Local variables: Local variables:
mode: sgml mode: sgml
sgml-omittag:t sgml-omittag:t

View File

@@ -1,42 +1,45 @@
<?xml version="1.0" encoding="iso-8859-1"?> <?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ --> <!-- $Revision$ -->
<sect1 id="language.function.literal"> <sect1 id="language.function.literal">
<title>literal</title> <title>literal</title>
<para> <para>
Literal tags allow a block of data to be taken literally. This is typically Literal tags allow a block of data to be taken literally. This is typically
used around javascript or stylesheet blocks where curly braces would used around javascript or stylesheet blocks where curly braces would
interfere with the template delimiter syntax. Anything within interfere with the template delimiter syntax. Anything within
{literal}{/literal} tags is not interpreted, but displayed as-is. If you {literal}{/literal} tags is not interpreted, but displayed as-is. If you
need template tags embedded in your literal block, consider using <link need template tags embedded in your literal block, consider using <link
linkend="language.function.ldelim">{ldelim}{rdelim}</link> to escape the linkend="language.function.ldelim">{ldelim}{rdelim}</link> to escape the
individual delimiters instead. individual delimiters instead.
</para> </para>
<example> <example>
<title>literal tags</title> <title>literal tags</title>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{literal} {literal}
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
function isblank(field) { function isblank(field) {
if (field.value == '') if (field.value == '')
{ return false; } { return false; }
else else
{ {
document.loginform.submit(); document.loginform.submit();
return true; return true;
} }
} }
// --> // -->
</script> </script>
{/literal} {/literal}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
<para>See also <link linkend="language.escaping">Escaping Smarty Parsing</link> </para> <para>
</sect1> See also
<link linkend="language.escaping">Escaping Smarty Parsing</link>.
</para>
</sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
Local variables: Local variables:

View File

@@ -1,23 +1,31 @@
<?xml version="1.0" encoding="iso-8859-1"?> <?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ --> <!-- $Revision$ -->
<sect1 id="language.function.php"> <sect1 id="language.function.php">
<title>php</title> <title>php</title>
<para> <para>
php tags allow php to be embedded directly into the template. They php tags allow php to be embedded directly into the template. They
will not be escaped, regardless of the <link will not be escaped, regardless of the <link
linkend="variable.php.handling">$php_handling</link> setting. This linkend="variable.php.handling">$php_handling</link> setting. This
is for advanced users only, not normally needed. is for advanced users only, not normally needed.
</para> </para>
<example> <example>
<title>php tags</title> <title>php tags</title>
<programlisting> <programlisting>
{php} <![CDATA[
// including a php script directly {php}
// from the template. // including a php script directly
include("/path/to/display_weather.php"); // from the template.
{/php}</programlisting> include("/path/to/display_weather.php");
</example> {/php}
<para>See also <link linkend="language.function.include.php">{include_php}</link>, <link linkend="language.function.include">{include}</link> and <link linkend="tips.componentized.templates">Componentized Templates</link></para> ]]>
</programlisting>
</example>
<para>
See also
<link linkend="language.function.include.php">{include_php}</link>,
<link linkend="language.function.include">{include}</link> and
<link linkend="tips.componentized.templates">Componentized Templates</link>.
</para>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
Local variables: Local variables:

View File

@@ -1,59 +1,62 @@
<?xml version="1.0" encoding="iso-8859-1"?> <?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ --> <!-- $Revision$ -->
<sect1 id="language.function.strip"> <sect1 id="language.function.strip">
<title>strip</title> <title>strip</title>
<para> <para>
Many times web designers run into the issue where white space and Many times web designers run into the issue where white space and
carriage returns affect the output of the rendered HTML (browser carriage returns affect the output of the rendered HTML (browser
"features"), so you must run all your tags together in the template "features"), so you must run all your tags together in the template
to get the desired results. This usually ends up in unreadable or to get the desired results. This usually ends up in unreadable or
unmanageable templates. unmanageable templates.
</para> </para>
<para> <para>
Anything within {strip}{/strip} tags in Smarty are stripped of the Anything within {strip}{/strip} tags in Smarty are stripped of the
extra spaces or carriage returns at the beginnings and ends of the extra spaces or carriage returns at the beginnings and ends of the
lines before they are displayed. This way you can keep your lines before they are displayed. This way you can keep your
templates readable, and not worry about extra white space causing templates readable, and not worry about extra white space causing
problems. problems.
</para> </para>
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
{strip}{/strip} does not affect the contents of template variables. {strip}{/strip} does not affect the contents of template variables.
See the <link linkend="language.modifier.strip">strip modifier See the <link linkend="language.modifier.strip">strip modifier
function</link>. function</link>.
</para> </para>
</note> </note>
<example> <example>
<title>strip tags</title> <title>strip tags</title>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{* the following will be all run into one line upon output *} {* the following will be all run into one line upon output *}
{strip} {strip}
<table border=0> <table border=0>
<tr> <tr>
<td> <td>
<A HREF="{$url}"> <A HREF="{$url}">
<font color="red">This is a test</font> <font color="red">This is a test</font>
</A> </A>
</td> </td>
</tr> </tr>
</table> </table>
{/strip} {/strip}
]]>
</programlisting>
OUTPUT: <para>
The above example will output:
</para>
<screen>
<![CDATA[
<table border=0><tr><td><A HREF="http://my.example.com"><font color="red">This is a test</font></A></td></tr></table> <table border=0><tr><td><A HREF="http://my.example.com"><font color="red">This is a test</font></A></td></tr></table>
]]> ]]>
</programlisting> </screen>
</example> </example>
<para> <para>
Notice that in the above example, all the lines begin and end Notice that in the above example, all the lines begin and end
with HTML tags. Be aware that all the lines are run together. with HTML tags. Be aware that all the lines are run together.
If you have plain text at the beginning or end of any line, If you have plain text at the beginning or end of any line,
they will be run together, and may not be desired results. they will be run together, and may not be desired results.
</para> </para>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file