cleaning words spacing, killing tabulations, using roles for programlisting..

This commit is contained in:
didou
2004-03-16 14:56:14 +00:00
parent 4c16d2b4d2
commit 40ed088eff
2 changed files with 656 additions and 528 deletions

View File

@@ -1,6 +1,6 @@
<part id="appendixes"> <part id="appendixes">
<title>Appendixes</title> <title>Appendixes</title>
<chapter id="troubleshooting"> <chapter id="troubleshooting">
<title>Troubleshooting</title> <title>Troubleshooting</title>
<para></para> <para></para>
<sect1 id="smarty.php.errors"> <sect1 id="smarty.php.errors">
@@ -10,17 +10,18 @@
or malformed variable names. If this happens, you will see an error or malformed variable names. If this happens, you will see an error
similar to the following: similar to the following:
</para> </para>
<example>
<example> <title>Smarty errors</title>
<title>Smarty errors</title> <screen>
<programlisting> <![CDATA[
Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah' Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah'
in /path/to/smarty/Smarty.class.php on line 1041 in /path/to/smarty/Smarty.class.php on line 1041
Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name
in /path/to/smarty/Smarty.class.php on line 1041</programlisting> in /path/to/smarty/Smarty.class.php on line 1041
</example> ]]>
</screen>
</example>
<para> <para>
Smarty shows you the template name, the line number and the error. Smarty shows you the template name, the line number and the error.
After that, the error consists of the actual line number in the Smarty After that, the error consists of the actual line number in the Smarty
@@ -33,11 +34,14 @@ Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name
parsing errors. parsing errors.
</para> </para>
<example> <example>
<title>PHP parsing errors</title> <title>PHP parsing errors</title>
<programlisting> <screen>
Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75</programlisting> <![CDATA[
</example> Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
]]>
</screen>
</example>
<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
@@ -50,8 +54,8 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
the template. the template.
</para> </para>
</sect1> </sect1>
</chapter> </chapter>
<chapter id="tips"> <chapter id="tips">
<title>Tips &amp; Tricks</title> <title>Tips &amp; Tricks</title>
<para> <para>
</para> </para>
@@ -64,10 +68,10 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
handle this, but there is a shorthand way with Smarty, using the handle this, but there is a shorthand way with Smarty, using the
<emphasis>default</emphasis> variable modifier. <emphasis>default</emphasis> variable modifier.
</para> </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>
<![CDATA[
{* the long way *} {* the long way *}
{if $title eq ""} {if $title eq ""}
@@ -79,8 +83,10 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
{* the short way *} {* the short way *}
{$title|default:"&amp;nbsp;"}</programlisting> {$title|default:"&amp;nbsp;"}
</example> ]]>
</programlisting>
</example>
</sect1> </sect1>
<sect1 id="tips.default.var.handling"> <sect1 id="tips.default.var.handling">
@@ -91,15 +97,18 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
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">assign</link> function.
</para> </para>
<example> <example>
<title>Assigning a template variable its default value</title> <title>Assigning a template variable its default value</title>
<programlisting> <programlisting>
<![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}</programlisting> {$title}
</example> ]]>
</programlisting>
</example>
</sect1> </sect1>
<sect1 id="tips.passing.vars"> <sect1 id="tips.passing.vars">
<title>Passing variable title to header template</title> <title>Passing variable title to header template</title>
@@ -110,10 +119,10 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
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 when
it is included. it is included.
</para> </para>
<example> <example>
<title>Passing the title variable to the header template</title> <title>Passing the title variable to the header template</title>
<programlisting> <programlisting>
<![CDATA[
mainpage.tpl mainpage.tpl
------------ ------------
@@ -143,8 +152,10 @@ header.tpl
footer.tpl footer.tpl
---------- ----------
&lt;/BODY&gt; &lt;/BODY&gt;
&lt;/HTML&gt;</programlisting> &lt;/HTML&gt;
</example> ]]>
</programlisting>
</example>
<para> <para>
When the main page is drawn, the title of "Main Page" is passed to the When the main page is drawn, the title of "Main Page" is passed to the
header.tpl, and will subsequently be used as the title. When the header.tpl, and will subsequently be used as the title. When the
@@ -168,9 +179,10 @@ footer.tpl
NOTE: As of Smarty 1.4.0, you can pass dates to Smarty as unix NOTE: As of Smarty 1.4.0, you can pass dates to Smarty as unix
timestamps, mysql timestamps, or any date parsable by strtotime(). timestamps, mysql timestamps, or any date parsable by strtotime().
</para> </para>
<example> <example>
<title>using date_format</title> <title>using date_format</title>
<programlisting> <programlisting>
<![CDATA[
{$startDate|date_format} {$startDate|date_format}
OUTPUT: OUTPUT:
@@ -187,16 +199,19 @@ OUTPUT:
{if $date1 &lt; $date2} {if $date1 &lt; $date2}
... ...
{/if}</programlisting> {/if}
</example> ]]>
</programlisting>
</example>
<para> <para>
When using {html_select_date} in a template, The programmer will most When using {html_select_date} 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>
<example> <example>
<title>converting form date elements back to a timestamp</title> <title>converting form date elements back to a timestamp</title>
<programlisting> <programlisting role="php">
<![CDATA[
// this assumes your form elements are named // this assumes your form elements are named
// startDate_Day, startDate_Month, startDate_Year // startDate_Day, startDate_Month, startDate_Year
@@ -212,8 +227,10 @@ function makeTimeStamp($year="",$month="",$day="")
$day = strftime("%d"); $day = strftime("%d");
return mktime(0,0,0,$month,$day,$year); return mktime(0,0,0,$month,$day,$year);
}</programlisting> }
</example> ]]>
</programlisting>
</example>
</sect1> </sect1>
<sect1 id="tips.wap"> <sect1 id="tips.wap">
<title>WAP/WML</title> <title>WAP/WML</title>
@@ -225,9 +242,12 @@ function makeTimeStamp($year="",$month="",$day="")
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> <programlisting role="php">
<![CDATA[
<?php
// be sure apache is configure for the .wml extensions! // be sure apache is configure for the .wml extensions!
// put this function somewhere in your application, or in Smarty.addons.php // put this function somewhere in your application, or in Smarty.addons.php
function insert_header($params) { function insert_header($params) {
@@ -238,8 +258,14 @@ function insert_header($params) {
return; return;
} }
// your Smarty template _must_ begin with the insert tag example: ?>
]]>
</programlisting>
<para>
your Smarty template <emphasis>must</emphasis> begin with the insert tag :
</para>
<programlisting>
<![CDATA[
{insert name=header content="Content-Type: text/vnd.wap.wml"} {insert name=header content="Content-Type: text/vnd.wap.wml"}
&lt;?xml version="1.0"?&gt; &lt;?xml version="1.0"?&gt;
@@ -263,8 +289,10 @@ Press OK to continue...
Pretty easy isn't it? Pretty easy isn't it?
&lt;/p&gt; &lt;/p&gt;
&lt;/card&gt; &lt;/card&gt;
&lt;/wml&gt;</programlisting> &lt;/wml&gt;
</example> ]]>
</programlisting>
</example>
</sect1> </sect1>
<sect1 id="tips.componentized.templates"> <sect1 id="tips.componentized.templates">
<title>Componentized Templates</title> <title>Componentized Templates</title>
@@ -283,13 +311,13 @@ Pretty easy isn't it?
You can do this by writing a custom plugin for fetching the content and You can do this by writing a custom plugin for fetching the content and
assigning it to a template variable. assigning it to a template variable.
</para> </para>
<example> <example>
<title>componentized template</title> <title>componentized template</title>
<programlisting> <programlisting role="php">
function.load_ticker.php <![CDATA[
--------------- <?php
&lt;?php // function.load_ticker.php
function smarty_function_load_ticker($params, &amp;$smarty) { function smarty_function_load_ticker($params, &amp;$smarty) {
// setup our function for fetching stock data // setup our function for fetching stock data
function fetch_ticker($params['symbol']) { function fetch_ticker($params['symbol']) {
@@ -304,8 +332,11 @@ function smarty_function_load_ticker($params, &amp;$smarty) {
// assign template variable // assign template variable
$smarty->assign($params['assign'],$ticker_info); $smarty->assign($params['assign'],$ticker_info);
} }
?&gt; ?>
]]>
</programlisting>
<programlisting>
<![CDATA[
index.tpl index.tpl
--------- ---------
@@ -313,8 +344,10 @@ index.tpl
{load_ticker symbol="YHOO" assign="ticker"} {load_ticker symbol="YHOO" assign="ticker"}
Stock Name: {$ticker.name} Stock Price: {$ticker.price}</programlisting> Stock Name: {$ticker.name} Stock Price: {$ticker.price}
</example> ]]>
</programlisting>
</example>
</sect1> </sect1>
<sect1 id="tips.obfuscating.email"> <sect1 id="tips.obfuscating.email">
<title>Obfuscating E-mail Addresses</title> <title>Obfuscating E-mail Addresses</title>
@@ -325,18 +358,18 @@ Stock Name: {$ticker.name} Stock Price: {$ticker.price}</programlisting>
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 mailto plugin. correctly in the browser. This is done with the mailto plugin.
</para> </para>
<example> <example>
<title>Example of Obfuscating an E-mail Address</title> <title>Example of Obfuscating an E-mail Address</title>
<programlisting> <programlisting>
<![CDATA[
index.tpl index.tpl
--------- ---------
Send inquiries to Send inquiries to
{mailto address=$EmailAddress encode="javascript" subject="Hello"} {mailto address=$EmailAddress encode="javascript" subject="Hello"}
]]>
</programlisting> </programlisting>
</example> </example>
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
@@ -345,8 +378,8 @@ Send inquiries to
</para> </para>
</note> </note>
</sect1> </sect1>
</chapter> </chapter>
<chapter id="resources"> <chapter id="resources">
<title>Resources</title> <title>Resources</title>
<para> <para>
Smarty's homepage is located at http://smarty.php.net/. Smarty's homepage is located at http://smarty.php.net/.
@@ -354,12 +387,12 @@ Send inquiries to
smarty-general-subscribe@lists.php.net. An archive of the mailing list can be smarty-general-subscribe@lists.php.net. An archive of the mailing list can be
viewed at http://marc.theaimsgroup.com/?l=smarty&amp;r=1&amp;w=2 viewed at http://marc.theaimsgroup.com/?l=smarty&amp;r=1&amp;w=2
</para> </para>
</chapter> </chapter>
<chapter id="bugs"> <chapter id="bugs">
<title>BUGS</title> <title>BUGS</title>
<para> <para>
Check the BUGS file that comes with the latest distribution of Smarty, or Check the BUGS file that comes with the latest distribution of Smarty, or
check the website. check the website.
</para> </para>
</chapter> </chapter>
</part> </part>

View File

@@ -49,28 +49,78 @@
Some of Smarty's features: Some of Smarty's features:
</para> </para>
<itemizedlist> <itemizedlist>
<listitem><para>It is extremely fast.</para></listitem> <listitem>
<listitem><para>It is efficient since the PHP parser does the <para>
dirty work.</para></listitem> It is extremely fast.
<listitem><para>No template parsing overhead, only compiles once.</para></listitem> </para>
<listitem><para>It is smart about recompiling only the template </listitem>
files that have changed.</para></listitem> <listitem>
<listitem><para>You can make <link linkend="language.custom.functions">custom <para>
functions</link> and custom <link linkend="language.modifiers">variable It is efficient since the PHP parser does the dirty work.
modifiers</link>, so the template language is extremely extensible.</para></listitem> </para>
<listitem><para>Configurable template delimiter tag syntax, so you can use </listitem>
{}, {{}}, &lt;!--{}--&gt;, etc.</para></listitem> <listitem>
<listitem><para>The if/elseif/else/endif constructs are passed to the <para>
No template parsing overhead, only compiles once.
</para>
</listitem>
<listitem>
<para>
It is smart about recompiling only the template files that have changed.
</para>
</listitem>
<listitem>
<para>
You can make <link linkend="language.custom.functions">custom functions</link>
and custom <link linkend="language.modifiers">variable modifiers</link>, so the
template language is extremely extensible.
</para>
</listitem>
<listitem>
<para>
Configurable template delimiter tag syntax, so you can use
{}, {{}}, &lt;!--{}--&gt;, etc.
</para>
</listitem>
<listitem>
<para>
The if/elseif/else/endif constructs are passed to the
PHP parser, so the {if ...} expression syntax can be as simple or as complex PHP parser, so the {if ...} expression syntax can be as simple or as complex
as you like.</para></listitem> as you like.
<listitem><para>Unlimited nesting of sections, ifs, etc. allowed.</para></listitem> </para>
<listitem><para>It is possible to embed PHP code right in your template files, </listitem>
<listitem>
<para>
Unlimited nesting of sections, ifs, etc. allowed.
</para>
</listitem>
<listitem>
<para>
It is possible to embed PHP code right in your template files,
although this may not be needed (nor recommended) although this may not be needed (nor recommended)
since the engine is so customizable.</para></listitem> since the engine is so customizable.
<listitem><para>Built-in caching support</para></listitem> </para>
<listitem><para>Arbitrary template sources</para></listitem> </listitem>
<listitem><para>Custom cache handling functions</para></listitem> <listitem>
<listitem><para>Plugin architecture</para></listitem> <para>
Built-in caching support
</para>
</listitem>
<listitem>
<para>
Arbitrary template sources
</para>
</listitem>
<listitem>
<para>
Custom cache handling functions
</para>
</listitem>
<listitem>
<para>
Plugin architecture
</para>
</listitem>
</itemizedlist> </itemizedlist>
</chapter> </chapter>
<chapter id="installation"> <chapter id="installation">
@@ -94,14 +144,16 @@
<example> <example>
<title>Smarty library files</title> <title>Smarty library files</title>
<screen> <screen>
<![CDATA[
Smarty.class.php Smarty.class.php
Smarty_Compiler.class.php Smarty_Compiler.class.php
Config_File.class.php Config_File.class.php
debug.tpl debug.tpl
/core/*.php (all of them) /core/*.php (all of them)
/plugins/*.php (all of them)</screen> /plugins/*.php (all of them)
]]>
</screen>
</example> </example>
<para> <para>
Smarty uses a PHP constant named <link Smarty uses a PHP constant named <link
linkend="constant.smarty.dir">SMARTY_DIR</link> which is the system linkend="constant.smarty.dir">SMARTY_DIR</link> which is the system
@@ -119,9 +171,14 @@ debug.tpl
<example> <example>
<title>Create Smarty instance of Smarty</title> <title>Create Smarty instance of Smarty</title>
<screen> <programlisting role="php">
<![CDATA[
<?php
require('Smarty.class.php'); require('Smarty.class.php');
$smarty = new Smarty;</screen> $smarty = new Smarty;
?>
]]>
</programlisting>
</example> </example>
<para> <para>
@@ -132,27 +189,42 @@ $smarty = new Smarty;</screen>
<example> <example>
<title>Supply absolute path to library file</title> <title>Supply absolute path to library file</title>
<screen> <programlisting role="php">
<![CDATA[
<?php
require('/usr/local/lib/php/Smarty/Smarty.class.php'); require('/usr/local/lib/php/Smarty/Smarty.class.php');
$smarty = new Smarty;</screen> $smarty = new Smarty;
?>
]]>
</programlisting>
</example> </example>
<example> <example>
<title>Add library directory to php_include path</title> <title>Add library directory to php_include path</title>
<screen> <programlisting role="php">
<![CDATA[
<?php
// Edit your php.ini file, add the Smarty library // Edit your php.ini file, add the Smarty library
// directory to the include_path and restart web server. // directory to the include_path and restart web server.
// Then the following should work: // Then the following should work:
require('Smarty.class.php'); require('Smarty.class.php');
$smarty = new Smarty;</screen> $smarty = new Smarty;
?>
]]>
</programlisting>
</example> </example>
<example> <example>
<title>Set SMARTY_DIR constant manually</title> <title>Set SMARTY_DIR constant manually</title>
<screen> <programlisting role="php">
define('SMARTY_DIR','/usr/local/lib/php/Smarty/'); <![CDATA[
require(SMARTY_DIR.'Smarty.class.php'); <?php
$smarty = new Smarty;</screen> define('SMARTY_DIR', '/usr/local/lib/php/Smarty/');
require(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty;
?>
]]>
</programlisting>
</example> </example>
<para> <para>
@@ -209,6 +281,7 @@ $smarty = new Smarty;</screen>
<example> <example>
<title>Example file structure</title> <title>Example file structure</title>
<screen> <screen>
<![CDATA[
/usr/local/lib/php/Smarty/Smarty.class.php /usr/local/lib/php/Smarty/Smarty.class.php
/usr/local/lib/php/Smarty/Smarty_Compiler.class.php /usr/local/lib/php/Smarty/Smarty_Compiler.class.php
/usr/local/lib/php/Smarty/Config_File.class.php /usr/local/lib/php/Smarty/Config_File.class.php
@@ -221,7 +294,9 @@ $smarty = new Smarty;</screen>
/web/www.mydomain.com/smarty/guestbook/configs/ /web/www.mydomain.com/smarty/guestbook/configs/
/web/www.mydomain.com/smarty/guestbook/cache/ /web/www.mydomain.com/smarty/guestbook/cache/
/web/www.mydomain.com/docs/guestbook/index.php</screen> /web/www.mydomain.com/docs/guestbook/index.php
]]>
</screen>
</example> </example>
<para> <para>
@@ -235,13 +310,15 @@ $smarty = new Smarty;</screen>
<example> <example>
<title>Setting file permissions</title> <title>Setting file permissions</title>
<screen> <programlisting role="shell">
<![CDATA[
chown nobody:nobody /web/www.mydomain.com/smarty/guestbook/templates_c/ chown nobody:nobody /web/www.mydomain.com/smarty/guestbook/templates_c/
chmod 770 /web/www.mydomain.com/smarty/guestbook/templates_c/ chmod 770 /web/www.mydomain.com/smarty/guestbook/templates_c/
chown nobody:nobody /web/www.mydomain.com/smarty/guestbook/cache/ chown nobody:nobody /web/www.mydomain.com/smarty/guestbook/cache/
chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/</screen> chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/
]]>
</programlisting>
</example> </example>
<note> <note>
@@ -262,13 +339,15 @@ chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/</screen>
<example> <example>
<title>Editing /web/www.mydomain.com/smarty/guestbook/templates/index.tpl</title> <title>Editing /web/www.mydomain.com/smarty/guestbook/templates/index.tpl</title>
<screen> <screen>
<![CDATA[
{* Smarty *} {* Smarty *}
Hello, {$name}!</screen> Hello, {$name}!
]]>
</screen>
</example> </example>
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
@@ -289,7 +368,10 @@ Hello, {$name}!</screen>
<example> <example>
<title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title> <title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title>
<screen> <programlisting role="php">
<![CDATA[
<?php
// load Smarty library // load Smarty library
require('Smarty.class.php'); require('Smarty.class.php');
@@ -302,7 +384,10 @@ $smarty->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/';
$smarty->assign('name','Ned'); $smarty->assign('name','Ned');
$smarty->display('index.tpl');</screen> $smarty->display('index.tpl');
?>
]]>
</programlisting>
</example> </example>
<note> <note>
@@ -344,7 +429,9 @@ $smarty->display('index.tpl');</screen>
<example> <example>
<title>Editing /php/includes/guestbook/setup.php</title> <title>Editing /php/includes/guestbook/setup.php</title>
<screen> <programlisting role="php">
<![CDATA[
<?php
// load Smarty library // load Smarty library
require('Smarty.class.php'); require('Smarty.class.php');
@@ -371,7 +458,10 @@ class Smarty_GuestBook extends Smarty {
$this->assign('app_name','Guest Book'); $this->assign('app_name','Guest Book');
} }
}</screen> }
?>
]]>
</programlisting>
</example> </example>
<para> <para>
@@ -380,7 +470,9 @@ class Smarty_GuestBook extends Smarty {
<example> <example>
<title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title> <title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title>
<screen> <programlisting role="php">
<![CDATA[
<?php
require('guestbook/setup.php'); require('guestbook/setup.php');
@@ -388,7 +480,10 @@ $smarty = new Smarty_GuestBook;
$smarty->assign('name','Ned'); $smarty->assign('name','Ned');
$smarty->display('index.tpl');</screen> $smarty->display('index.tpl');
?>
]]>
</programlisting>
</example> </example>
<para> <para>