This commit is contained in:
pete_morgan
2006-02-18 13:18:16 +00:00
parent baa6910c46
commit aabfda3c63
9 changed files with 52 additions and 55 deletions

View File

@@ -21,8 +21,7 @@
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{* the long way *} {* the long way *}
{if $title eq ''}
{if $title eq ""}
&nbsp; &nbsp;
{else} {else}
{$title} {$title}
@@ -30,8 +29,7 @@
{* the short way *} {* the short way *}
{$title|default:'&nbsp;'}
{$title|default:"&nbsp;"}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
@@ -54,7 +52,7 @@
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{* do this somewhere at the top of your template *} {* do this somewhere at the top of your template *}
{assign var="title" value=$title|default:"no title"} {assign var='title' value=$title|default:'no title'}
{* if $title was empty, it now contains the value "no title" when you print it *} {* if $title was empty, it now contains the value "no title" when you print it *}
{$title} {$title}
@@ -74,7 +72,8 @@
is common to split those out into their own templates and is common to split those out into their own templates and
<link linkend="language.function.include">{include}</link> them. <link linkend="language.function.include">{include}</link> them.
But what if the header needs to have a different title, depending on But what if the header needs to have a different title, depending on
what page you are coming from? You can pass the title to the header when what page you are coming from? You can pass the title to the header
as an <link linkend="language.syntax.attributes">attribute</link> when
it is included. it is included.
</para> </para>
@@ -82,38 +81,45 @@
<title>Passing the title variable to the header template</title> <title>Passing the title variable to the header template</title>
<para> <para>
<filename>mainpage.tpl</filename> <filename>mainpage.tpl</filename> - When the main page is drawn, the title of "Main Page" is passed to the
<filename>header.tpl</filename>, and will subsequently be used as the title.
</para> </para>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{include file='header.tpl' title='Main Page'}
{include file="header.tpl" title="Main Page"}
{* template body goes here *} {* template body goes here *}
{include file="footer.tpl"} {include file='footer.tpl'}
]]> ]]>
</programlisting> </programlisting>
<para> <para>
<filename>archives.tpl</filename> <filename>archives.tpl</filename> - When the
archives page is drawn, the title will be "Archives". Notice in the
archive example, we are using a variable from the
<filename>archives_page.conf</filename>
file instead of a hard coded variable.
</para> </para>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{config_load file="archive_page.conf"} {config_load file='archive_page.conf'}
{include file="header.tpl" title=#archivePageTitle#} {include file='header.tpl' title=#archivePageTitle#}
{* template body goes here *} {* template body goes here *}
{include file="footer.tpl"} {include file='footer.tpl'}
]]> ]]>
</programlisting> </programlisting>
<para> <para>
<filename>header.tpl</filename> <filename>header.tpl</filename> - Notice that "BC News" is
printed if the $title variable is not set, using the
<link linkend="language.modifier.default">default</link>
variable modifier.
</para> </para>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
<html> <html>
<head> <head>
<title>{$title|default:"BC News"}</title> <title>{$title|default:'BC News'}</title>
</head> </head>
<body> <body>
]]> ]]>
@@ -129,27 +135,17 @@
]]> ]]>
</programlisting> </programlisting>
</example> </example>
<para>
When the main page is drawn, the title of "Main Page" is passed to the
<filename>header.tpl</filename>, and will subsequently be used as the title. When the
archives page is drawn, the title will be "Archives". Notice in the
archive example, we are using a variable from the
<filename>archives_page.conf</filename>
file instead of a hard coded variable. Also notice that "BC News" is
printed if the $title variable is not set, using the
<link linkend="language.modifier.default">default</link>
variable modifier.
</para>
</sect1> </sect1>
<sect1 id="tips.dates"> <sect1 id="tips.dates">
<title>Dates</title> <title>Dates</title>
<para> <para>
As a rule of thumb, always pass dates to Smarty as timestamps. This As a rule of thumb, always pass dates to Smarty as
allows template designers to use <link <ulink url="&url.php-manual;time">timestamps</ulink>. This
linkend="language.modifier.date.format">date_format</link> for full allows template designers to use the <link
control over date formatting, and also makes it easy to compare dates if linkend="language.modifier.date.format">date_format</link> modifier
necessary. for full control over date formatting, and also makes it easy to
compare dates if necessary.
</para> </para>
<note> <note>
<para> <para>
@@ -196,7 +192,7 @@ Jan 4, 2001
</example> </example>
<para> <para>
When using <link linkend="language.function.html.select.date">{html_select_date}</link> When using <link linkend="language.function.html.select.date">{html_select_date}</link>
in a template, The programmer will most in a template, the programmer will most
likely want to convert the output from the form back into timestamp likely want to convert the output from the form back into timestamp
format. Here is a function to help you with that. format. Here is a function to help you with that.
</para> </para>

View File

@@ -57,7 +57,7 @@
Be careful when capturing <link Be careful when capturing <link
linkend="language.function.insert">{insert}</link> linkend="language.function.insert">{insert}</link>
output. If you have output. If you have
<link linkend="caching">caching</link> <link linkend="caching">$caching</link>
enabled and you have enabled and you have
<link linkend="language.function.insert">{insert}</link> <link linkend="language.function.insert">{insert}</link>
commands that you expect to run commands that you expect to run
@@ -93,13 +93,13 @@
<link linkend="language.function.popup">{popup}</link> <link linkend="language.function.popup">{popup}</link>
function</para> function</para>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{capture name=some_content assign=popText} {capture name=some_content assign=popText}
.... some content .... .... some popup content ....
{/capture} {/capture}
<a href="#" {popup caption='Help' text=$popText}>help</a> <a href="#" {popup caption='Help' text=$popText}>help</a>
]]> ]]>
</programlisting> </programlisting>
</example> </example>

View File

@@ -63,7 +63,7 @@
<para> <para>
{include_php} tags are used to include a php script in your template. {include_php} tags are used to include a php script in your template.
If <link linkend="variable.security">security is enabled</link>, If <link linkend="variable.security">$security</link> is enabled,
then the php script must be located in the <link then the php script must be located in the <link
linkend="variable.trusted.dir">$trusted_dir</link> path. linkend="variable.trusted.dir">$trusted_dir</link> path.
The {include_php} tag must have the attribute The {include_php} tag must have the attribute
@@ -97,9 +97,9 @@
<?php <?php
// load in variables from a mysql db and assign them to the template // load in variables from a mysql db and assign them to the template
require_once("MySQL.class.php"); require_once('MySQL.class.php');
$sql = new MySQL; $sql = new MySQL;
$sql->query("select * from site_nav_sections order by name",SQL_ALL); $sql->query('select * from site_nav_sections order by name',SQL_ALL);
$this->assign('sections',$sql->record); $this->assign('sections',$sql->record);
?> ?>
@@ -111,7 +111,7 @@ $this->assign('sections',$sql->record);
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{* absolute path, or relative to $trusted_dir *} {* absolute path, or relative to $trusted_dir *}
{include_php file="/path/to/load_nav.php"} {include_php file='/path/to/load_nav.php'}
{foreach item="curr_section" from=$sections} {foreach item="curr_section" from=$sections}
<a href="{$curr_section.url}">{$curr_section.name}</a><br /> <a href="{$curr_section.url}">{$curr_section.name}</a><br />

View File

@@ -6,7 +6,8 @@
{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 <emphasis>'file'</emphasis>,
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,

View File

@@ -19,9 +19,9 @@
<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 see the
<link linkend="language.modifier.strip">strip modifier</link>. <link linkend="language.modifier.strip">strip modifier</link> instead.
</para> </para>
</note> </note>
<example> <example>

View File

@@ -33,7 +33,7 @@ $smarty->display('index.tpl');
<![CDATA[ <![CDATA[
{$articleTitle} {$articleTitle}
{$articleTitle|strip} {$articleTitle|strip}
{$articleTitle|strip:"&nbsp;"} {$articleTitle|strip:'&nbsp;'}
]]> ]]>
</programlisting> </programlisting>
<para> <para>

View File

@@ -16,7 +16,7 @@
</methodsynopsis> </methodsynopsis>
<para> <para>
This only works if <link This only works if <link
linkend="variable.caching">$caching</link> is set to true. See also the linkend="variable.caching">$caching</link> is set to true; see the
<link linkend="caching">caching section</link>. <link linkend="caching">caching section</link>.
</para> </para>
<example> <example>

View File

@@ -6,7 +6,7 @@
<refpurpose>dynamically register resources</refpurpose> <refpurpose>dynamically register resources</refpurpose>
</refnamediv> </refnamediv>
<refsect1> <refsect1>
<title>Descrption</title> <title>Description</title>
<methodsynopsis> <methodsynopsis>
<type>void</type><methodname>register_resource</methodname> <type>void</type><methodname>register_resource</methodname>
<methodparam><type>string</type><parameter>name</parameter></methodparam> <methodparam><type>string</type><parameter>name</parameter></methodparam>

View File

@@ -8,11 +8,11 @@
or <link linkend="api.fetch">fetch()</link>. or <link linkend="api.fetch">fetch()</link>.
Let's say that a call to display('index.tpl') may have several Let's say that a call to display('index.tpl') may have several
different output contents depending on some condition, and you want different output contents depending on some condition, and you want
separate caches for each one. You can do this by passing a cache_id as the separate caches for each one. You can do this by passing a $cache_id as the
second parameter to the function call. second parameter to the function call.
</para> </para>
<example> <example>
<title>passing a cache_id to display()</title> <title>passing a $cache_id to display()</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php