Tidy up of formatting

This commit is contained in:
pete_morgan
2006-09-27 04:32:52 +00:00
parent 409efbdd68
commit ecf7820fdc
3 changed files with 172 additions and 115 deletions

View File

@@ -2,13 +2,36 @@
<!-- $Revision$ --> <!-- $Revision$ -->
<chapter id="resources"> <chapter id="resources">
<title>Resources</title> <title>Resources</title>
<para> <para>Smarty's homepage is located at
Smarty's homepage is located at <ulink <ulink url="&url.smarty;">&url.smarty;</ulink>
url="&url.smarty;">&url.smarty;</ulink>.
You can join the mailing list by sending an e-mail to
&ml.general.sub;. An archive of the mailing list can
be viewed at <ulink url="&url.ml.archive;">&url.ml.archive;</ulink>.
</para> </para>
<itemizedlist>
<listitem><para>
You can join the mailing list by sending an e-mail to
<literal>&ml.general.sub;</literal>. An archive of the mailing list can
be viewed at <ulink url="&url.ml.archive;">here</ulink>
</para></listitem>
<listitem><para>
Forums are at <ulink url="&url.forums;">&url.forums;</ulink>
</para></listitem>
<listitem><para>
The wiki is located at <ulink url="&url.wiki;">&url.wiki;</ulink>
</para></listitem>
<listitem><para>
Join the chat at <ulink url="&url.wiki;">irc.freenode.net#smarty</ulink>
</para></listitem>
<listitem><para>
FAQ's are <ulink url="&url.faq_1;">here</ulink> and <ulink url="&url.faq_2;">here</ulink>
</para></listitem>
</itemizedlist>
</chapter> </chapter>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
Local variables: Local variables:

View File

@@ -8,14 +8,22 @@
<title>Blank Variable Handling</title> <title>Blank Variable Handling</title>
<para> <para>
There may be times when you want to print a default value for an empty There may be times when you want to print a default value for an empty
variable instead of printing nothing, such as printing "&amp;nbsp;" so that variable instead of printing nothing, such as printing
table backgrounds work properly. Many would use an <literal>&amp;nbsp;</literal> so that
<link linkend="language.function.if">{if}</link> statement to html table backgrounds work properly. Many would use an
handle this, but there is a shorthand way with Smarty, using the <link linkend="language.function.if"><varname>{if}</varname></link>
<link statement to handle this, but there is a shorthand way with Smarty, using
linkend="language.modifier.default"><emphasis>default</emphasis></link> the <link linkend="language.modifier.default"><varname>default</varname>
variable modifier. </link> variable modifier.
<note>
<para><quote>Undefined variable</quote> errors will show if PHP
<ulink url="&url.php-manual;error_reporting">
<varname>error_reporting()</varname></ulink> is <constant>E_ALL</constant>
and a variable had not been assigned to Smarty.
</para> </para>
</note>
</para>
<example> <example>
<title>Printing &amp;nbsp; when a variable is empty</title> <title>Printing &amp;nbsp; when a variable is empty</title>
<programlisting> <programlisting>
@@ -27,25 +35,28 @@
{$title} {$title}
{/if} {/if}
{* the short way *} {* the short way *}
{$title|default:'&nbsp;'} {$title|default:'&nbsp;'}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
<para> <para>
See also <link linkend="language.modifier.default">default</link> See also <link linkend="language.modifier.default">
and <link linkend="tips.default.var.handling">Default Variable Handling</link>. <varname>default</varname></link> modifier and
</para> <link linkend="tips.default.var.handling">default variable handling</link>.
</para>
</sect1> </sect1>
<sect1 id="tips.default.var.handling"> <sect1 id="tips.default.var.handling">
<title>Default Variable Handling</title> <title>Default Variable Handling</title>
<para> <para>
If a variable is used frequently throughout your templates, applying If a variable is used frequently throughout your templates, applying
the default modifier every time it is mentioned can get a bit ugly. You the <link linkend="language.modifier.default"><varname>default</varname>
</link> modifier every time it is mentioned can get a bit ugly. You
can remedy this by assigning the variable its default value with the can remedy this by assigning the variable its default value with the
<link linkend="language.function.assign">{assign}</link> function. <link linkend="language.function.assign"><varname>{assign}</varname></link>
function.
</para> </para>
<example> <example>
<title>Assigning a template variable its default value</title> <title>Assigning a template variable its default value</title>
@@ -54,14 +65,15 @@
{* 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 use it *}
{$title} {$title}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
<para> <para>
See also <link linkend="language.modifier.default">default</link> and See also
<link linkend="tips.blank.var.handling">Blank Variable Handling</link>. <link linkend="language.modifier.default"><varname>default</varname></link>
modifier and <link linkend="tips.blank.var.handling">blank variable handling</link>.
</para> </para>
</sect1> </sect1>
@@ -70,7 +82,8 @@
<para> <para>
When the majority of your templates use the same headers and footers, it When the majority of your templates use the same headers and footers, it
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">
<varname>{include}</varname></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 what page you are coming from? You can pass the title to the header
as an <link linkend="language.syntax.attributes">attribute</link> when as an <link linkend="language.syntax.attributes">attribute</link> when
@@ -81,7 +94,8 @@
<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> - When the main page is drawn, the title of "Main Page" is passed to the <filename>mainpage.tpl</filename> - When the main page is drawn,
the title of <quote>Main Page</quote> is passed to the
<filename>header.tpl</filename>, and will subsequently be used as the title. <filename>header.tpl</filename>, and will subsequently be used as the title.
</para> </para>
<programlisting> <programlisting>
@@ -94,15 +108,15 @@
<para> <para>
<filename>archives.tpl</filename> - When the <filename>archives.tpl</filename> - When the
archives page is drawn, the title will be "Archives". Notice in the archives page is drawn, the title will be <quote>Archives</quote>.
archive example, we are using a variable from the Notice in the archive example, we are using a variable from the
<filename>archives_page.conf</filename> <filename>archives_page.conf</filename>
file instead of a hard coded variable. 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'}
@@ -110,9 +124,9 @@
</programlisting> </programlisting>
<para> <para>
<filename>header.tpl</filename> - Notice that "Smarty News" is <filename>header.tpl</filename> - Notice that <quote>Smarty News</quote> is
printed if the $title variable is not set, using the printed if the <literal>$title</literal> variable is not set, using the
<link linkend="language.modifier.default">default</link> <link linkend="language.modifier.default"><varname>default</varname></link>
variable modifier. variable modifier.
</para> </para>
<programlisting> <programlisting>
@@ -143,19 +157,12 @@
As a rule of thumb, always pass dates to Smarty as As a rule of thumb, always pass dates to Smarty as
<ulink url="&url.php-manual;time">timestamps</ulink>. This <ulink url="&url.php-manual;time">timestamps</ulink>. This
allows template designers to use the <link allows template designers to use the <link
linkend="language.modifier.date.format">date_format</link> modifier linkend="language.modifier.date.format"><varname>date_format</varname>
for full control over date formatting, and also makes it easy to </link> modifier for full control over date formatting, and also makes it
compare dates if necessary. easy to compare dates if necessary.
</para> </para>
<note>
<para>
As of Smarty 1.4.0, you can pass dates to Smarty as unix
timestamps, mysql timestamps, or any date parsable by
<ulink url="&url.php-manual;strtotime">strtotime()</ulink>.
</para>
</note>
<example> <example>
<title>using date_format</title> <title>Using date_format</title>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{$startDate|date_format} {$startDate|date_format}
@@ -166,7 +173,7 @@
</para> </para>
<screen> <screen>
<![CDATA[ <![CDATA[
Jan 4, 2001 Jan 4, 2009
]]> ]]>
</screen> </screen>
<programlisting> <programlisting>
@@ -179,25 +186,28 @@ Jan 4, 2001
</para> </para>
<screen> <screen>
<![CDATA[ <![CDATA[
2001/01/04 2009/01/04
]]> ]]>
</screen> </screen>
<para>
Dates can be compared in the template by timestamps with:
</para>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{if $date1 < $date2} {if $order_date < $invoice_date}
... ...do something..
{/if} {/if}
]]> ]]>
</programlisting> </programlisting>
</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">
in a template, the programmer will most <varname>{html_select_date}</varname></link> in a template, the programmer
likely want to convert the output from the form back into timestamp will most likely want to convert the output from the form back into
format. Here is a function to help you with that. timestamp format. Here is a function to help you with that.
</para> </para>
<example> <example>
<title>converting form date elements back to a timestamp</title> <title>Converting form date elements back to a timestamp</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
@@ -210,13 +220,13 @@ $startDate = makeTimeStamp($startDate_Year, $startDate_Month, $startDate_Day);
function makeTimeStamp($year='', $month='', $day='') function makeTimeStamp($year='', $month='', $day='')
{ {
if(empty($year)) { if(empty($year)) {
$year = strftime("%Y"); $year = strftime('%Y');
} }
if(empty($month)) { if(empty($month)) {
$month = strftime("%m"); $month = strftime('%m');
} }
if(empty($day)) { if(empty($day)) {
$day = strftime("%d"); $day = strftime('%d');
} }
return mktime(0, 0, 0, $month, $day, $year); return mktime(0, 0, 0, $month, $day, $year);
@@ -228,10 +238,14 @@ function makeTimeStamp($year='', $month='', $day='')
<para> <para>
See also See also
<link linkend="language.function.html.select.date">{html_select_date}</link>, <link linkend="language.function.html.select.date">
<link linkend="language.function.html.select.time">{html_select_time}</link>, <varname>{html_select_date}</varname></link>,
<link linkend="language.modifier.date.format">date_format</link> <link linkend="language.function.html.select.time">
and <link linkend="language.variables.smarty.now">$smarty.now</link>, <varname>{html_select_time}</varname></link>,
<link linkend="language.modifier.date.format">
<varname>date_format</varname></link>
and <link linkend="language.variables.smarty.now">
<parameter>$smarty.now</parameter></link>,
</para> </para>
</sect1> </sect1>
@@ -245,13 +259,13 @@ function makeTimeStamp($year='', $month='', $day='')
function that prints the header. If you are using function that prints the header. If you are using
<link linkend="caching">caching</link>, that won't <link linkend="caching">caching</link>, that won't
work so we'll do it using the work so we'll do it using the
<link linkend="language.function.insert">{insert}</link> <link linkend="language.function.insert"><varname>{insert}</varname></link>
tag; remember {insert} tags are not tag; remember <varname>{insert}</varname> tags are not
cached! Be sure that there is nothing output to the browser before the cached! Be sure that there is nothing output to the browser before the
template, or else the header may fail. template, or else the header may fail.
</para> </para>
<example> <example>
<title>using {insert} to write a WML Content-Type header</title> <title>Using {insert} to write a WML Content-Type header</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
@@ -304,14 +318,16 @@ function insert_header($params)
</programlisting> </programlisting>
</example> </example>
</sect1> </sect1>
<sect1 id="tips.componentized.templates"> <sect1 id="tips.componentized.templates">
<title>Componentized Templates</title> <title>Componentized Templates</title>
<para> <para>
Traditionally, programming templates into your applications goes as Traditionally, programming templates into your applications goes as
follows: First, you accumulate your variables within your PHP follows: First, you accumulate your variables within your PHP
application, (maybe with database queries.) Then, you instantiate your application, (maybe with database queries.) Then, you instantiate your
Smarty object, <link linkend="api.assign">assign()</link> the variables and Smarty object, <link linkend="api.assign"><varname>assign()</varname></link>
<link linkend="api.display">display()</link> the template. So lets the variables and <link linkend="api.display"><varname>display()</varname>
</link> the template. So lets
say for example we have a stock ticker on our template. We would say for example we have a stock ticker on our template. We would
collect the stock data in our application, then assign these variables collect the stock data in our application, then assign these variables
in the template and display it. Now wouldn't it be nice if you could in the template and display it. Now wouldn't it be nice if you could
@@ -327,7 +343,8 @@ function insert_header($params)
<para> <para>
<filename>function.load_ticker.php</filename> - <filename>function.load_ticker.php</filename> -
drop file in drop file in
<link linkend="variable.plugins.dir">$plugins directory</link> <link linkend="variable.plugins.dir">
<parameter>$plugins directory</parameter></link>
</para> </para>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
@@ -364,27 +381,29 @@ Stock Name: {$ticker.name} Stock Price: {$ticker.price}
</programlisting> </programlisting>
</example> </example>
<para> <para>
See also <link linkend="language.function.include.php">{include_php}</link>, See also
<link linkend="language.function.include">{include}</link> and <link linkend="language.function.include.php"><varname>{include_php}</varname></link>,
<link linkend="language.function.php">{php}</link>. <link linkend="language.function.include"><varname>{include}</varname></link>
and
<link linkend="language.function.php"><varname>{php}</varname></link>.
</para> </para>
</sect1> </sect1>
<sect1 id="tips.obfuscating.email"> <sect1 id="tips.obfuscating.email">
<title>Obfuscating E-mail Addresses</title> <title>Obfuscating E-mail Addresses</title>
<para> <para>
Do you ever wonder how your E-mail address gets on so many spam mailing Do you ever wonder how your email address gets on so many spam mailing
lists? One way spammers collect E-mail addresses is from web pages. To lists? One way spammers collect email addresses is from web pages. To
help combat this problem, you can make your E-mail address show up in help combat this problem, you can make your email address show up in
scrambled javascript in the HTML source, yet it it will look and work scrambled javascript in the HTML source, yet it it will look and work
correctly in the browser. This is done with the correctly in the browser. This is done with the
<link linkend="language.function.mailto">{mailto}</link> plugin. <link linkend="language.function.mailto">
<varname>{mailto}</varname></link> plugin.
</para> </para>
<example> <example>
<title>Example of Obfuscating an E-mail Address</title> <title>Example of template the Obfuscating an email address</title>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{* in the template *}
<div id="contact">Send inquiries to <div id="contact">Send inquiries to
{mailto address=$EmailAddress encode='javascript' subject='Hello'} {mailto address=$EmailAddress encode='javascript' subject='Hello'}
</div> </div>
@@ -395,13 +414,15 @@ Stock Name: {$ticker.name} Stock Price: {$ticker.price}
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
This method isn't 100% foolproof. A spammer could conceivably program his This method isn't 100% foolproof. A spammer could conceivably program his
e-mail collector to decode these values, but not likely....hopefully..yet ... wheres that quantum computer :-?. e-mail collector to decode these values, but not likely....
hopefully..yet ... wheres that quantum computer :-?.
</para> </para>
</note> </note>
<para> <para>
See also <link linkend="language.modifier.escape">escape</link> See also
and <link linkend="language.modifier.escape"><varname>escape</varname></link>
<link linkend="language.function.mailto">{mailto}</link>. modifier and
<link linkend="language.function.mailto"><varname>{mailto}</varname></link>.
</para> </para>
</sect1> </sect1>
</chapter> </chapter>

View File

@@ -45,12 +45,12 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
<para> <para>
When you encounter a PHP parsing error, the error line number will When you encounter a PHP parsing error, the error line number will
correspond to the compiled PHP script, not the template itself. Usually correspond to the compiled PHP script, NOT the template itself. Usually
you can look at the template and spot the syntax error. Here are some you can look at the template and spot the syntax error. Here are some
common things to look for: missing close tags for common things to look for: missing close tags for
<link linkend="language.function.if">{if}{/if}</link> or <link linkend="language.function.if"><varname>{if}{/if}</varname></link> or
<link linkend="language.function.if">{section}{/section}</link>, <link linkend="language.function.if"><varname>{section}{/section}</varname>
or syntax of logic within an {if} tag. If you </link>, or syntax of logic within an <varname>{if}</varname> tag. If you
can't find the error, you might have to open the compiled PHP file and can't find the error, you might have to open the compiled PHP file and
go to the line number to figure out where the corresponding error is in go to the line number to figure out where the corresponding error is in
the template. the template.
@@ -60,33 +60,32 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
<example> <example>
<title>Other common errors</title> <title>Other common errors</title>
<itemizedlist> <screen>
<listitem>
<screen>
<![CDATA[ <![CDATA[
Warning: Smarty error: unable to read resource: "index.tpl" in... Warning: Smarty error: unable to read resource: "index.tpl" in...
or or
Warning: Smarty error: unable to read resource: "site.conf" in... Warning: Smarty error: unable to read resource: "site.conf" in...
]]> ]]>
</screen> </screen>
<para> <para>
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para> <para>
The <link linkend="variable.template.dir">$template_dir</link> The <link linkend="variable.template.dir">
is incorrect, doesn't exist or <parameter>$template_dir</parameter></link> is incorrect, doesn't exist or
the file <filename>index.tpl</filename> is not in the the file <filename>index.tpl</filename> is not in the
<filename class="directory">templates/</filename> directory <filename class="directory">templates/</filename> directory
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
A <link linkend="language.function.config.load">{config_load}</link> A <link linkend="language.function.config.load">
<varname>{config_load}</varname></link>
function is within a template (or function is within a template (or
<link linkend="api.config.load">config_load()</link> <link linkend="api.config.load"><varname>config_load()</varname></link>
has been called) and either has been called) and either
<link linkend="variable.config.dir">$config_dir</link> <link linkend="variable.config.dir"><parameter>$config_dir</parameter>
is incorrent , does not exist or </link> is incorrent , does not exist or
<filename>site.conf</filename> is not in the directory. <filename>site.conf</filename> is not in the directory.
</para> </para>
</listitem> </listitem>
@@ -94,35 +93,41 @@ Warning: Smarty error: unable to read resource: "site.conf" in...
</itemizedlist> </itemizedlist>
</para> </para>
</listitem><listitem>
<screen> <screen>
<![CDATA[ <![CDATA[
Fatal error: Smarty error: the $compile_dir 'templates_c' does not exist, Fatal error: Smarty error: the $compile_dir 'templates_c' does not exist,
or is not a directory... or is not a directory...
]]> ]]>
</screen> </screen>
<itemizedlist>
<listitem>
<para> <para>
Either the Either the
<link linkend="variable.compile.dir">$compile_dir</link> <link linkend="variable.compile.dir">
is incorrectly set, the directory does not exist, <parameter>$compile_dir</parameter></link>is incorrectly set,
or <filename>templates_c</filename> is a the directory does not exist, or <filename>templates_c</filename> is a
file and not a directory. file and not a directory.
</para> </para>
</listitem><listitem> </listitem>
</itemizedlist>
<screen> <screen>
<![CDATA[ <![CDATA[
Fatal error: Smarty error: unable to write to $compile_dir '.... Fatal error: Smarty error: unable to write to $compile_dir '....
]]> ]]>
</screen> </screen>
<itemizedlist>
<listitem>
<para> <para>
The <link linkend="variable.compile.dir">$compile_dir</link> The <link linkend="variable.compile.dir">
is not writable by the web server. See the bottom of the <parameter>$compile_dir</parameter></link> is not writable by the web server.
See the bottom of the
<link linkend="installing.smarty.basic">installing smarty</link> page <link linkend="installing.smarty.basic">installing smarty</link> page
for permissions. for more about permissions.
</para> </para>
</listitem>
</listitem><listitem> </itemizedlist>
<screen> <screen>
<![CDATA[ <![CDATA[
@@ -130,27 +135,34 @@ Fatal error: Smarty error: the $cache_dir 'cache' does not exist,
or is not a directory. in /.. or is not a directory. in /..
]]> ]]>
</screen> </screen>
<itemizedlist>
<listitem>
<para> <para>
This means that This means that
<link linkend="variable.caching">$caching</link> is enabled and either; <link linkend="variable.caching">
<parameter>$caching</parameter></link> is enabled and either;
the the
<link linkend="variable.cache.dir">$cache_dir</link> <link linkend="variable.cache.dir"><parameter>$cache_dir</parameter></link>
is incorrectly set, the directory does not exist, is incorrectly set, the directory does not exist,
or <filename>cache</filename> is a or <filename>cache/</filename> is a
file and not a directory. file and not a directory.
</para> </para>
</listitem>
</listitem><listitem> </itemizedlist>
<screen> <screen>
<![CDATA[ <![CDATA[
Fatal error: Smarty error: unable to write to $cache_dir '/... Fatal error: Smarty error: unable to write to $cache_dir '/...
]]> ]]>
</screen> </screen>
<itemizedlist>
<listitem>
<para> <para>
This means that This means that
<link linkend="variable.caching">$caching</link> is enabled and the <link linkend="variable.caching"><parameter>$caching</parameter></link> is
<link linkend="variable.cache.dir">$cache_dir</link> enabled and the <link linkend="variable.cache.dir">
<parameter>$cache_dir</parameter></link>
is not writable by the web server. See the bottom of the is not writable by the web server. See the bottom of the
<link linkend="installing.smarty.basic">installing smarty</link> page <link linkend="installing.smarty.basic">installing smarty</link> page
for permissions. for permissions.
@@ -162,9 +174,10 @@ Fatal error: Smarty error: unable to write to $cache_dir '/...
<para> <para>
See also See also
<link linkend="chapter.debugging.console">debugging</link>, <link linkend="chapter.debugging.console">debugging</link>,
<link linkend="variable.error.reporting">$error_reporting</link> <link linkend="variable.error.reporting">
<parameter>$error_reporting</parameter></link>
and and
<link linkend="api.trigger.error">trigger_error()</link>. <link linkend="api.trigger.error"><varname>trigger_error()</varname></link>.
</para> </para>
</sect1> </sect1>
</chapter> </chapter>