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">
<title>Appendixes</title>
<chapter id="troubleshooting">
<chapter id="troubleshooting">
<title>Troubleshooting</title>
<para></para>
<sect1 id="smarty.php.errors">
@@ -10,17 +10,18 @@
or malformed variable names. If this happens, you will see an error
similar to the following:
</para>
<example>
<title>Smarty errors</title>
<programlisting>
<example>
<title>Smarty errors</title>
<screen>
<![CDATA[
Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah'
in /path/to/smarty/Smarty.class.php on line 1041
Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name
in /path/to/smarty/Smarty.class.php on line 1041</programlisting>
</example>
in /path/to/smarty/Smarty.class.php on line 1041
]]>
</screen>
</example>
<para>
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
@@ -33,11 +34,14 @@ Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name
parsing errors.
</para>
<example>
<title>PHP parsing errors</title>
<programlisting>
Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75</programlisting>
</example>
<example>
<title>PHP parsing errors</title>
<screen>
<![CDATA[
Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
]]>
</screen>
</example>
<para>
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.
</para>
</sect1>
</chapter>
<chapter id="tips">
</chapter>
<chapter id="tips">
<title>Tips &amp; Tricks</title>
<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
<emphasis>default</emphasis> variable modifier.
</para>
<example>
<title>Printing &amp;nbsp; when a variable is empty</title>
<programlisting>
<example>
<title>Printing &amp;nbsp; when a variable is empty</title>
<programlisting>
<![CDATA[
{* the long way *}
{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 *}
{$title|default:"&amp;nbsp;"}</programlisting>
</example>
{$title|default:"&amp;nbsp;"}
]]>
</programlisting>
</example>
</sect1>
<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
<link linkend="language.function.assign">assign</link> function.
</para>
<example>
<title>Assigning a template variable its default value</title>
<programlisting>
<example>
<title>Assigning a template variable its default value</title>
<programlisting>
<![CDATA[
{* do this somewhere at the top of your template *}
{assign var="title" value=$title|default:"no title"}
{* if $title was empty, it now contains the value "no title" when you print it *}
{$title}</programlisting>
</example>
{$title}
]]>
</programlisting>
</example>
</sect1>
<sect1 id="tips.passing.vars">
<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
it is included.
</para>
<example>
<title>Passing the title variable to the header template</title>
<programlisting>
<example>
<title>Passing the title variable to the header template</title>
<programlisting>
<![CDATA[
mainpage.tpl
------------
@@ -143,8 +152,10 @@ header.tpl
footer.tpl
----------
&lt;/BODY&gt;
&lt;/HTML&gt;</programlisting>
</example>
&lt;/HTML&gt;
]]>
</programlisting>
</example>
<para>
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
@@ -168,9 +179,10 @@ footer.tpl
NOTE: As of Smarty 1.4.0, you can pass dates to Smarty as unix
timestamps, mysql timestamps, or any date parsable by strtotime().
</para>
<example>
<title>using date_format</title>
<programlisting>
<example>
<title>using date_format</title>
<programlisting>
<![CDATA[
{$startDate|date_format}
OUTPUT:
@@ -187,16 +199,19 @@ OUTPUT:
{if $date1 &lt; $date2}
...
{/if}</programlisting>
</example>
{/if}
]]>
</programlisting>
</example>
<para>
When using {html_select_date} in a template, The programmer will most
likely want to convert the output from the form back into timestamp
format. Here is a function to help you with that.
</para>
<example>
<title>converting form date elements back to a timestamp</title>
<programlisting>
<example>
<title>converting form date elements back to a timestamp</title>
<programlisting role="php">
<![CDATA[
// this assumes your form elements are named
// startDate_Day, startDate_Month, startDate_Year
@@ -212,8 +227,10 @@ function makeTimeStamp($year="",$month="",$day="")
$day = strftime("%d");
return mktime(0,0,0,$month,$day,$year);
}</programlisting>
</example>
}
]]>
</programlisting>
</example>
</sect1>
<sect1 id="tips.wap">
<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
template, or else the header may fail.
</para>
<example>
<title>using insert to write a WML Content-Type header</title>
<programlisting>
<example>
<title>using insert to write a WML Content-Type header</title>
<programlisting role="php">
<![CDATA[
<?php
// be sure apache is configure for the .wml extensions!
// put this function somewhere in your application, or in Smarty.addons.php
function insert_header($params) {
@@ -238,8 +258,14 @@ function insert_header($params) {
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"}
&lt;?xml version="1.0"?&gt;
@@ -263,8 +289,10 @@ Press OK to continue...
Pretty easy isn't it?
&lt;/p&gt;
&lt;/card&gt;
&lt;/wml&gt;</programlisting>
</example>
&lt;/wml&gt;
]]>
</programlisting>
</example>
</sect1>
<sect1 id="tips.componentized.templates">
<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
assigning it to a template variable.
</para>
<example>
<title>componentized template</title>
<programlisting>
function.load_ticker.php
---------------
<example>
<title>componentized template</title>
<programlisting role="php">
<![CDATA[
<?php
&lt;?php
// function.load_ticker.php
function smarty_function_load_ticker($params, &amp;$smarty) {
// setup our function for fetching stock data
function fetch_ticker($params['symbol']) {
@@ -304,8 +332,11 @@ function smarty_function_load_ticker($params, &amp;$smarty) {
// assign template variable
$smarty->assign($params['assign'],$ticker_info);
}
?&gt;
?>
]]>
</programlisting>
<programlisting>
<![CDATA[
index.tpl
---------
@@ -313,8 +344,10 @@ index.tpl
{load_ticker symbol="YHOO" assign="ticker"}
Stock Name: {$ticker.name} Stock Price: {$ticker.price}</programlisting>
</example>
Stock Name: {$ticker.name} Stock Price: {$ticker.price}
]]>
</programlisting>
</example>
</sect1>
<sect1 id="tips.obfuscating.email">
<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
correctly in the browser. This is done with the mailto plugin.
</para>
<example>
<title>Example of Obfuscating an E-mail Address</title>
<programlisting>
<example>
<title>Example of Obfuscating an E-mail Address</title>
<programlisting>
<![CDATA[
index.tpl
---------
Send inquiries to
{mailto address=$EmailAddress encode="javascript" subject="Hello"}
</programlisting>
</example>
]]>
</programlisting>
</example>
<note>
<title>Technical Note</title>
<para>
@@ -345,8 +378,8 @@ Send inquiries to
</para>
</note>
</sect1>
</chapter>
<chapter id="resources">
</chapter>
<chapter id="resources">
<title>Resources</title>
<para>
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
viewed at http://marc.theaimsgroup.com/?l=smarty&amp;r=1&amp;w=2
</para>
</chapter>
<chapter id="bugs">
</chapter>
<chapter id="bugs">
<title>BUGS</title>
<para>
Check the BUGS file that comes with the latest distribution of Smarty, or
check the website.
</para>
</chapter>
</chapter>
</part>

View File

@@ -49,28 +49,78 @@
Some of Smarty's features:
</para>
<itemizedlist>
<listitem><para>It is extremely fast.</para></listitem>
<listitem><para>It is efficient since the PHP parser does the
dirty work.</para></listitem>
<listitem><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
<listitem>
<para>
It is extremely fast.
</para>
</listitem>
<listitem>
<para>
It is efficient since the PHP parser does the dirty work.
</para>
</listitem>
<listitem>
<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
as you like.</para></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,
as you like.
</para>
</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)
since the engine is so customizable.</para></listitem>
<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>
since the engine is so customizable.
</para>
</listitem>
<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>
</chapter>
<chapter id="installation">
@@ -94,14 +144,16 @@
<example>
<title>Smarty library files</title>
<screen>
<![CDATA[
Smarty.class.php
Smarty_Compiler.class.php
Config_File.class.php
debug.tpl
/core/*.php (all of them)
/plugins/*.php (all of them)</screen>
/plugins/*.php (all of them)
]]>
</screen>
</example>
<para>
Smarty uses a PHP constant named <link
linkend="constant.smarty.dir">SMARTY_DIR</link> which is the system
@@ -119,9 +171,14 @@ debug.tpl
<example>
<title>Create Smarty instance of Smarty</title>
<screen>
<programlisting role="php">
<![CDATA[
<?php
require('Smarty.class.php');
$smarty = new Smarty;</screen>
$smarty = new Smarty;
?>
]]>
</programlisting>
</example>
<para>
@@ -132,27 +189,42 @@ $smarty = new Smarty;</screen>
<example>
<title>Supply absolute path to library file</title>
<screen>
<programlisting role="php">
<![CDATA[
<?php
require('/usr/local/lib/php/Smarty/Smarty.class.php');
$smarty = new Smarty;</screen>
$smarty = new Smarty;
?>
]]>
</programlisting>
</example>
<example>
<title>Add library directory to php_include path</title>
<screen>
<programlisting role="php">
<![CDATA[
<?php
// Edit your php.ini file, add the Smarty library
// directory to the include_path and restart web server.
// Then the following should work:
require('Smarty.class.php');
$smarty = new Smarty;</screen>
$smarty = new Smarty;
?>
]]>
</programlisting>
</example>
<example>
<title>Set SMARTY_DIR constant manually</title>
<screen>
define('SMARTY_DIR','/usr/local/lib/php/Smarty/');
require(SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty;</screen>
<programlisting role="php">
<![CDATA[
<?php
define('SMARTY_DIR', '/usr/local/lib/php/Smarty/');
require(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty;
?>
]]>
</programlisting>
</example>
<para>
@@ -209,6 +281,7 @@ $smarty = new Smarty;</screen>
<example>
<title>Example file structure</title>
<screen>
<![CDATA[
/usr/local/lib/php/Smarty/Smarty.class.php
/usr/local/lib/php/Smarty/Smarty_Compiler.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/cache/
/web/www.mydomain.com/docs/guestbook/index.php</screen>
/web/www.mydomain.com/docs/guestbook/index.php
]]>
</screen>
</example>
<para>
@@ -235,13 +310,15 @@ $smarty = new Smarty;</screen>
<example>
<title>Setting file permissions</title>
<screen>
<programlisting role="shell">
<![CDATA[
chown nobody:nobody /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/
chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/</screen>
chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/
]]>
</programlisting>
</example>
<note>
@@ -262,13 +339,15 @@ chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/</screen>
<example>
<title>Editing /web/www.mydomain.com/smarty/guestbook/templates/index.tpl</title>
<screen>
<![CDATA[
{* Smarty *}
Hello, {$name}!</screen>
Hello, {$name}!
]]>
</screen>
</example>
<note>
<title>Technical Note</title>
<para>
@@ -289,7 +368,10 @@ Hello, {$name}!</screen>
<example>
<title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title>
<screen>
<programlisting role="php">
<![CDATA[
<?php
// load Smarty library
require('Smarty.class.php');
@@ -302,7 +384,10 @@ $smarty->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/';
$smarty->assign('name','Ned');
$smarty->display('index.tpl');</screen>
$smarty->display('index.tpl');
?>
]]>
</programlisting>
</example>
<note>
@@ -344,7 +429,9 @@ $smarty->display('index.tpl');</screen>
<example>
<title>Editing /php/includes/guestbook/setup.php</title>
<screen>
<programlisting role="php">
<![CDATA[
<?php
// load Smarty library
require('Smarty.class.php');
@@ -371,7 +458,10 @@ class Smarty_GuestBook extends Smarty {
$this->assign('app_name','Guest Book');
}
}</screen>
}
?>
]]>
</programlisting>
</example>
<para>
@@ -380,7 +470,9 @@ class Smarty_GuestBook extends Smarty {
<example>
<title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title>
<screen>
<programlisting role="php">
<![CDATA[
<?php
require('guestbook/setup.php');
@@ -388,7 +480,10 @@ $smarty = new Smarty_GuestBook;
$smarty->assign('name','Ned');
$smarty->display('index.tpl');</screen>
$smarty->display('index.tpl');
?>
]]>
</programlisting>
</example>
<para>