Clean up:

- domain.com => example.com, as suggested by RFC 2606
- fix and introduce more dockbook tags
- fix white spaces and use CDATA sections
- add some paras to make the text more reader friendly
This commit is contained in:
didou
2004-11-21 02:04:01 +00:00
parent 659563b570
commit 9d4d0c08a1
18 changed files with 810 additions and 787 deletions

View File

@@ -307,10 +307,7 @@ function smarty_function_load_ticker($params, &$smarty)
</programlisting> </programlisting>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
index.tpl {* in index.tpl *}
---------
{* Smarty *}
{load_ticker symbol="YHOO" assign="ticker"} {load_ticker symbol="YHOO" assign="ticker"}
@@ -332,8 +329,7 @@ Stock Name: {$ticker.name} Stock Price: {$ticker.price}
<title>Example of Obfuscating an E-mail Address</title> <title>Example of Obfuscating an E-mail Address</title>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
index.tpl {* in index.tpl *}
---------
Send inquiries to Send inquiries to
{mailto address=$EmailAddress encode="javascript" subject="Hello"} {mailto address=$EmailAddress encode="javascript" subject="Hello"}

View File

@@ -4,10 +4,12 @@
<title>Smarty - the compiling PHP template engine</title> <title>Smarty - the compiling PHP template engine</title>
<authorgroup id="authors"> <authorgroup id="authors">
<author> <author>
<firstname>Monte</firstname><surname>Ohrt &lt;monte@ispi.net&gt;</surname> <firstname>Monte</firstname>
<surname>Ohrt &lt;monte@ispi.net&gt;</surname>
</author> </author>
<author> <author>
<firstname>Andrei</firstname><surname>Zmievski &lt;andrei@php.net&gt;</surname> <firstname>Andrei</firstname>
<surname>Zmievski &lt;andrei@php.net&gt;</surname>
</author> </author>
</authorgroup> </authorgroup>
<pubdate>&build-date;</pubdate> <pubdate>&build-date;</pubdate>

View File

@@ -32,7 +32,7 @@ Intro = """This is a value that spans more
# hidden section # hidden section
[.Database] [.Database]
host=my.domain.com host=my.example.com
db=ADDRESSBOOK db=ADDRESSBOOK
user=php-user user=php-user
pass=foobar pass=foobar

View File

@@ -79,7 +79,7 @@
{* body of template goes here *} {* body of template goes here *}
{include file="footer.tpl" logo="http://my.domain.com/logo.gif"}</programlisting> {include file="footer.tpl" logo="http://my.example.com/logo.gif"}</programlisting>
</example> </example>
<para> <para>
Use the syntax for <link Use the syntax for <link

View File

@@ -174,21 +174,21 @@ name: John Smith&lt;br&gt;
address: 253 N 45th&lt;br&gt; address: 253 N 45th&lt;br&gt;
home phone: 555-555-5555&lt;br&gt; home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt; cell phone: 555-555-5555&lt;br&gt;
e-mail: john@mydomain.com&lt;br&gt; e-mail: john@myexample.com&lt;br&gt;
&lt;p&gt; &lt;p&gt;
id: 1001&lt;br&gt; id: 1001&lt;br&gt;
name: Jack Jones&lt;br&gt; name: Jack Jones&lt;br&gt;
address: 417 Mulberry ln&lt;br&gt; address: 417 Mulberry ln&lt;br&gt;
home phone: 555-555-5555&lt;br&gt; home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt; cell phone: 555-555-5555&lt;br&gt;
e-mail: jack@mydomain.com&lt;br&gt; e-mail: jack@myexample.com&lt;br&gt;
&lt;p&gt; &lt;p&gt;
id: 1002&lt;br&gt; id: 1002&lt;br&gt;
name: Jane Munson&lt;br&gt; name: Jane Munson&lt;br&gt;
address: 5605 apple st&lt;br&gt; address: 5605 apple st&lt;br&gt;
home phone: 555-555-5555&lt;br&gt; home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt; cell phone: 555-555-5555&lt;br&gt;
e-mail: jane@mydomain.com&lt;br&gt; e-mail: jane@myexample.com&lt;br&gt;
&lt;p&gt;</programlisting> &lt;p&gt;</programlisting>
</example> </example>
@@ -210,15 +210,15 @@ OUTPUT:
name: John Smith&lt;br&gt; name: John Smith&lt;br&gt;
home: 555-555-5555&lt;br&gt; home: 555-555-5555&lt;br&gt;
cell: 555-555-5555&lt;br&gt; cell: 555-555-5555&lt;br&gt;
e-mail: john@mydomain.com&lt;p&gt; e-mail: john@myexample.com&lt;p&gt;
name: Jack Jones&lt;br&gt; name: Jack Jones&lt;br&gt;
home phone: 555-555-5555&lt;br&gt; home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt; cell phone: 555-555-5555&lt;br&gt;
e-mail: jack@mydomain.com&lt;p&gt; e-mail: jack@myexample.com&lt;p&gt;
name: Jane Munson&lt;br&gt; name: Jane Munson&lt;br&gt;
home phone: 555-555-5555&lt;br&gt; home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt; cell phone: 555-555-5555&lt;br&gt;
e-mail: jane@mydomain.com&lt;p&gt;</programlisting> e-mail: jane@myexample.com&lt;p&gt;</programlisting>
</example> </example>

View File

@@ -44,7 +44,7 @@
OUTPUT: OUTPUT:
<table border=0><tr><td><A HREF="http://my.domain.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> </programlisting>
</example> </example>

View File

@@ -71,13 +71,13 @@
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{* include some javascript in your template *} {* include some javascript in your template *}
{fetch file="/export/httpd/www.domain.com/docs/navbar.js"} {fetch file="/export/httpd/www.example.com/docs/navbar.js"}
{* embed some weather text in your template from another web site *} {* embed some weather text in your template from another web site *}
{fetch file="http://www.myweather.com/68502/"} {fetch file="http://www.myweather.com/68502/"}
{* fetch a news headline file via ftp *} {* fetch a news headline file via ftp *}
{fetch file="ftp://user:password@ftp.domain.com/path/to/currentheadlines.txt"} {fetch file="ftp://user:password@ftp.example.com/path/to/currentheadlines.txt"}
{* assign the fetched contents to a template variable *} {* assign the fetched contents to a template variable *}
{fetch file="http://www.myweather.com/68502/" assign="weather"} {fetch file="http://www.myweather.com/68502/" assign="weather"}

View File

@@ -31,25 +31,23 @@
<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 text to display, default is <entry>the text to display, default is the e-mail address</entry>
the e-mail address</entry>
</row> </row>
<row> <row>
<entry>encode</entry> <entry>encode</entry>
<entry>string</entry> <entry>string</entry>
<entry>No</entry> <entry>No</entry>
<entry><emphasis>none</emphasis></entry> <entry><emphasis>none</emphasis></entry>
<entry>How to encode the e-mail. <entry>How to encode the e-mail. Can be one of <literal>none</literal>,
Can be one of none, <literal>hex</literal> or <literal>javascript</literal>.</entry>
hex or javascript.</entry>
</row> </row>
<row> <row>
<entry>cc</entry> <entry>cc</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>e-mail addresses to carbon copy. <entry>e-mail addresses to carbon copy. Separate entries by a comma.
Separate entries by a comma.</entry> </entry>
</row> </row>
<row> <row>
<entry>bcc</entry> <entry>bcc</entry>
@@ -71,24 +69,21 @@
<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>newsgroups to post to. <entry>newsgroups to post to. Separate entries by a comma.</entry>
Separate entries by a comma.</entry>
</row> </row>
<row> <row>
<entry>followupto</entry> <entry>followupto</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>addresses to follow up to. <entry>addresses to follow up to. Separate entries by a comma.</entry>
Separate entries by a comma.</entry>
</row> </row>
<row> <row>
<entry>extra</entry> <entry>extra</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>any extra information you <entry>any extra information you want passed to the link, such
want passed to the link, such
as style sheet classes</entry> as style sheet classes</entry>
</row> </row>
</tbody> </tbody>
@@ -109,26 +104,26 @@
<example> <example>
<title>mailto</title> <title>mailto</title>
<programlisting> <programlisting>
{mailto address="me@domain.com"} {mailto address="me@example.com"}
{mailto address="me@domain.com" text="send me some mail"} {mailto address="me@example.com" text="send me some mail"}
{mailto address="me@domain.com" encode="javascript"} {mailto address="me@example.com" encode="javascript"}
{mailto address="me@domain.com" encode="hex"} {mailto address="me@example.com" encode="hex"}
{mailto address="me@domain.com" subject="Hello to you!"} {mailto address="me@example.com" subject="Hello to you!"}
{mailto address="me@domain.com" cc="you@domain.com,they@domain.com"} {mailto address="me@example.com" cc="you@example.com,they@example.com"}
{mailto address="me@domain.com" extra='class="email"'} {mailto address="me@example.com" extra='class="email"'}
OUTPUT: OUTPUT:
&lt;a href="mailto:me@domain.com" &gt;me@domain.com&lt;/a&gt; &lt;a href="mailto:me@example.com" &gt;me@example.com&lt;/a&gt;
&lt;a href="mailto:me@domain.com" &gt;send me some mail&lt;/a&gt; &lt;a href="mailto:me@example.com" &gt;send me some mail&lt;/a&gt;
&lt;script type="text/javascript" language="javascript"&gt;eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%6 &lt;script type="text/javascript" language="javascript"&gt;eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%6
9%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d% 9%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%
61%69%6e%2e%63%6f%6d%22%20%3e%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%3c%2f%61%3e 61%69%6e%2e%63%6f%6d%22%20%3e%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%3c%2f%61%3e
%27%29%3b'))&lt;/script&gt; %27%29%3b'))&lt;/script&gt;
&lt;a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d" &gt;&#x6d;&#x65;&#x40;&#x64;&#x6f;&#x6d;&#x61;&#x69;&#x6e;&#x2e;&#x63;&#x6f;&#x6d;&lt;/a&gt; &lt;a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d" &gt;&#x6d;&#x65;&#x40;&#x64;&#x6f;&#x6d;&#x61;&#x69;&#x6e;&#x2e;&#x63;&#x6f;&#x6d;&lt;/a&gt;
&lt;a href="mailto:me@domain.com?subject=Hello%20to%20you%21" &gt;me@domain.com&lt;/a&gt; &lt;a href="mailto:me@example.com?subject=Hello%20to%20you%21" &gt;me@example.com&lt;/a&gt;
&lt;a href="mailto:me@domain.com?cc=you@domain.com%2Cthey@domain.com" &gt;me@domain.com&lt;/a&gt; &lt;a href="mailto:me@example.com?cc=you@example.com%2Cthey@example.com" &gt;me@example.com&lt;/a&gt;
&lt;a href="mailto:me@domain.com" class="email"&gt;me@domain.com&lt;/a&gt;</programlisting> &lt;a href="mailto:me@example.com" class="email"&gt;me@example.com&lt;/a&gt;</programlisting>
</example> </example>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file

View File

@@ -396,15 +396,19 @@
<example> <example>
<title>popup</title> <title>popup</title>
<programlisting> <programlisting>
<![CDATA[
{* popup_init must be called once at the top of the page *} {* popup_init must be called once at the top of the page *}
{popup_init src="/javascripts/overlib.js"} {popup_init src="/javascripts/overlib.js"}
{* create a link with a popup window when you move your mouse over *} {* create a link with a popup window when you move your mouse over *}
&lt;A href="mypage.html" {popup text="This link takes you to my page!"}&gt;mypage&lt;/A&gt; <a href="mypage.html" {popup text="This link takes you to my page!"}>mypage</a>
{* you can use html, links, etc in your popup text *} {* you can use html, links, etc in your popup text *}
&lt;A href="mypage.html" {popup sticky=true caption="mypage contents" <a href="mypage.html" {popup sticky=true caption="mypage contents"
text="&lt;UL&gt;&lt;LI&gt;links&lt;LI&gt;pages&lt;LI&gt;images&lt;/UL&gt;" snapx=10 snapy=10}&gt;mypage&lt;/A&gt;</programlisting> text="<ul><li>links</li><li>pages</li><li>images</li></ul>" snapx=10
snapy=10}>mypage</a>
]]>
</programlisting>
</example> </example>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file

View File

@@ -18,7 +18,7 @@
<title>displaying request variables</title> <title>displaying request variables</title>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{* display value of page from URL (GET) http://www.domain.com/index.php?page=foo *} {* display value of page from URL (GET) http://www.example.com/index.php?page=foo *}
{$smarty.get.page} {$smarty.get.page}
{* display the variable "page" from a form (POST) *} {* display the variable "page" from a form (POST) *}

View File

@@ -9,12 +9,15 @@
Smarty is a template engine for PHP. More specifically, it facilitates a Smarty is a template engine for PHP. More specifically, it facilitates a
manageable way to separate application logic and content from its manageable way to separate application logic and content from its
presentation. This is best described in a situation where the application presentation. This is best described in a situation where the application
programmer and the template designer play different roles, or in most cases programmer and the template designer play different roles, or in most
are not the same person. For example, let's say you are creating a web page cases are not the same person.
that is displaying a newspaper article. The article headline, tagline, </para>
author and body are content elements, they contain no information about how <para>
they will be presented. They are passed into Smarty by the application, For example, let's say you are creating a web page that is displaying a
then the template designer edits the templates and uses a combination of newspaper article. The article headline, tagline, author and body are
content elements, they contain no information about how they will be
presented. They are passed into Smarty by the application, then the
template designer edits the templates and uses a combination of
HTML tags and template tags to format the presentation of these elements HTML tags and template tags to format the presentation of these elements
(HTML tables, background colors, font sizes, style sheets, etc.) One day (HTML tables, background colors, font sizes, style sheets, etc.) One day
the programmer needs to change the way the article content is retrieved (a the programmer needs to change the way the article content is retrieved (a
@@ -35,16 +38,16 @@
presentation logic. This does not mean that Smarty forces a separation of presentation logic. This does not mean that Smarty forces a separation of
business and presentation logic. Smarty has no knowledge of which is which, business and presentation logic. Smarty has no knowledge of which is which,
so placing business logic in the template is your own doing. Also, if you so placing business logic in the template is your own doing. Also, if you
desire NO logic in your templates you certainly can do so by boiling the desire <emphasis>no</emphasis> logic in your templates you certainly can
content down to text and variables only. do so by boiling the content down to text and variables only.
</para> </para>
<para> <para>
One of the unique aspects about Smarty is the template compiling. This means One of the unique aspects about Smarty is the template compiling. This
Smarty reads the template files and creates PHP scripts from them. Once means Smarty reads the template files and creates PHP scripts from them.
they are created, they are executed from then on. Therefore there is no Once they are created, they are executed from then on. Therefore there is
costly template file parsing for each request, and each template can take no costly template file parsing for each request, and each template can
full advantage of PHP compiler cache solutions such as Zend Accelerator take full advantage of PHP compiler cache solutions such as Zend
(<ulink url="&url.zend;">&url.zend;</ulink>) or PHP Accelerator Accelerator (<ulink url="&url.zend;">&url.zend;</ulink>) or PHP Accelerator
(<ulink url="&url.php-accelerator;">&url.php-accelerator;</ulink>). (<ulink url="&url.php-accelerator;">&url.php-accelerator;</ulink>).
</para> </para>
<para> <para>
@@ -73,8 +76,10 @@
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
You can make <link linkend="language.custom.functions">custom functions</link> You can make <link
and custom <link linkend="language.modifiers">variable modifiers</link>, so the linkend="language.custom.functions">custom functions</link>
and custom <link
linkend="language.modifiers">variable modifiers</link>, so the
template language is extremely extensible. template language is extremely extensible.
</para> </para>
</listitem> </listitem>
@@ -87,8 +92,8 @@
<listitem> <listitem>
<para> <para>
The if/elseif/else/endif constructs are passed to the 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
as you like. complex as you like.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
@@ -98,9 +103,9 @@
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
It is possible to embed PHP code right in your template files, It is possible to embed PHP code right in your template files, although
although this may not be needed (nor recommended) this may not be needed (nor recommended) since the engine is so
since the engine is so customizable. customizable.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
@@ -160,9 +165,9 @@ debug.tpl
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
filepath Smarty library directory. Basically, if your application can find filepath Smarty library directory. Basically, if your application can find
the <emphasis>Smarty.class.php</emphasis> file, you do not need to set the <filename>Smarty.class.php</filename> file, you do not need to set
SMARTY_DIR, Smarty will figure it out on its own. Therefore, if SMARTY_DIR, Smarty will figure it out on its own. Therefore, if
<emphasis>Smarty.class.php</emphasis> is not in your include_path, or you <filename>Smarty.class.php</filename> is not in your include_path, or you
do not supply an absolute path to it in your application, then you must do not supply an absolute path to it in your application, then you must
define SMARTY_DIR manually. SMARTY_DIR <emphasis>must</emphasis> include a define SMARTY_DIR manually. SMARTY_DIR <emphasis>must</emphasis> include a
trailing slash. trailing slash.
@@ -185,7 +190,7 @@ $smarty = new Smarty;
<para> <para>
Try running the above script. If you get an error saying the Try running the above script. If you get an error saying the
<emphasis>Smarty.class.php</emphasis> file could not be found, you have to <filename>Smarty.class.php</filename> file could not be found, you have to
do one of the following: do one of the following:
</para> </para>
@@ -232,18 +237,20 @@ $smarty = new Smarty;
<para> <para>
Now that the library files are in place, it's time to setup the Smarty Now that the library files are in place, it's time to setup the Smarty
directories for your application. Smarty requires four directories which directories for your application. Smarty requires four directories which
are (by default) named <emphasis>templates</emphasis>, are (by default) named <filename class="directory">templates</filename>,
<emphasis>templates_c</emphasis>, <emphasis>configs</emphasis> and <filename class="directory">templates_c</filename>, <filename
<emphasis>cache</emphasis>. Each of these are definable by the Smarty class class="directory">configs</filename> and <filename
properties <emphasis>$template_dir</emphasis>, class="directory">cache</filename>. Each of these are definable by the
<emphasis>$compile_dir</emphasis>, <emphasis>$config_dir</emphasis>, and Smarty class properties <varname>$template_dir</varname>,
<emphasis>$cache_dir</emphasis> respectively. It is highly recommended <varname>$compile_dir</varname>, <varname>$config_dir</varname>, and
<varname>$cache_dir</varname> respectively. It is highly recommended
that you setup a separate set of these directories for each application that you setup a separate set of these directories for each application
that will use Smarty. that will use Smarty.
</para> </para>
<para> <para>
Be sure you know the location of your web server document root. In our Be sure you know the location of your web server document root. In our
example, the document root is "/web/www.mydomain.com/docs/". The Smarty example, the document root is <filename
class="directory">/web/www.example.com/docs/</filename>. The Smarty
directories are only accessed by the Smarty library and never accessed directories are only accessed by the Smarty library and never accessed
directly by the web browser. Therefore to avoid any security concerns, it directly by the web browser. Therefore to avoid any security concerns, it
is recommended to place these directories <emphasis>outside</emphasis> of is recommended to place these directories <emphasis>outside</emphasis> of
@@ -255,13 +262,14 @@ $smarty = new Smarty;
of a directory naming convention. You can use the same environment for any of a directory naming convention. You can use the same environment for any
application, just replace "guestbook" with the name of your app. We'll application, just replace "guestbook" with the name of your app. We'll
place our Smarty directories under place our Smarty directories under
"/web/www.mydomain.com/smarty/guestbook/". <filename
class="directory">/web/www.example.com/smarty/guestbook/</filename>.
</para> </para>
<para> <para>
You will need as least one file under your document root, and that is the You will need as least one file under your document root, and that is the
script accessed by the web browser. We will call our script "index.php", script accessed by the web browser. We will call our script
and place it in a subdirectory under the document root called <filename>index.php</filename>, and place it in a subdirectory under the
"/guestbook/". document root called <filename class="directory">/guestbook/</filename>.
</para> </para>
<note> <note>
@@ -269,7 +277,7 @@ $smarty = new Smarty;
<para> <para>
It is convenient to setup the web server so that "index.php" can be It is convenient to setup the web server so that "index.php" can be
identified as the default directory index, so if you access identified as the default directory index, so if you access
"http://www.mydomain.com/guestbook/", the index.php script will be executed "http://www.example.com/guestbook/", the index.php script will be executed
without "index.php" in the URL. In Apache you can set this up by adding without "index.php" in the URL. In Apache you can set this up by adding
"index.php" onto the end of your DirectoryIndex setting (separate each "index.php" onto the end of your DirectoryIndex setting (separate each
entry with a space.) entry with a space.)
@@ -291,12 +299,12 @@ $smarty = new Smarty;
/usr/local/lib/php/Smarty/internals/*.php /usr/local/lib/php/Smarty/internals/*.php
/usr/local/lib/php/Smarty/plugins/*.php /usr/local/lib/php/Smarty/plugins/*.php
/web/www.mydomain.com/smarty/guestbook/templates/ /web/www.example.com/smarty/guestbook/templates/
/web/www.mydomain.com/smarty/guestbook/templates_c/ /web/www.example.com/smarty/guestbook/templates_c/
/web/www.mydomain.com/smarty/guestbook/configs/ /web/www.example.com/smarty/guestbook/configs/
/web/www.mydomain.com/smarty/guestbook/cache/ /web/www.example.com/smarty/guestbook/cache/
/web/www.mydomain.com/docs/guestbook/index.php /web/www.example.com/docs/guestbook/index.php
]]> ]]>
</screen> </screen>
</example> </example>
@@ -314,11 +322,11 @@ $smarty = new Smarty;
<title>Setting file permissions</title> <title>Setting file permissions</title>
<programlisting role="shell"> <programlisting role="shell">
<![CDATA[ <![CDATA[
chown nobody:nobody /web/www.mydomain.com/smarty/guestbook/templates_c/ chown nobody:nobody /web/www.example.com/smarty/guestbook/templates_c/
chmod 770 /web/www.mydomain.com/smarty/guestbook/templates_c/ chmod 770 /web/www.example.com/smarty/guestbook/templates_c/
chown nobody:nobody /web/www.mydomain.com/smarty/guestbook/cache/ chown nobody:nobody /web/www.example.com/smarty/guestbook/cache/
chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/ chmod 770 /web/www.example.com/smarty/guestbook/cache/
]]> ]]>
</programlisting> </programlisting>
</example> </example>
@@ -339,7 +347,7 @@ chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/
</para> </para>
<example> <example>
<title>Editing /web/www.mydomain.com/smarty/guestbook/templates/index.tpl</title> <title>Editing /web/www.example.com/smarty/guestbook/templates/index.tpl</title>
<screen> <screen>
<![CDATA[ <![CDATA[
@@ -369,7 +377,7 @@ Hello, {$name}!
</para> </para>
<example> <example>
<title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title> <title>Editing /web/www.example.com/docs/guestbook/index.php</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
@@ -379,10 +387,10 @@ require('Smarty.class.php');
$smarty = new Smarty; $smarty = new Smarty;
$smarty->template_dir = '/web/www.mydomain.com/smarty/guestbook/templates/'; $smarty->template_dir = '/web/www.example.com/smarty/guestbook/templates/';
$smarty->compile_dir = '/web/www.mydomain.com/smarty/guestbook/templates_c/'; $smarty->compile_dir = '/web/www.example.com/smarty/guestbook/templates_c/';
$smarty->config_dir = '/web/www.mydomain.com/smarty/guestbook/configs/'; $smarty->config_dir = '/web/www.example.com/smarty/guestbook/configs/';
$smarty->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/'; $smarty->cache_dir = '/web/www.example.com/smarty/guestbook/cache/';
$smarty->assign('name','Ned'); $smarty->assign('name','Ned');
@@ -396,17 +404,18 @@ $smarty->display('index.tpl');
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
In our example, we are setting absolute paths to all of the Smarty In our example, we are setting absolute paths to all of the Smarty
directories. If '/web/www.mydomain.com/smarty/guestbook/' is within your directories. If <filename
PHP include_path, then these settings are not necessary. However, it is class="directory">/web/www.example.com/smarty/guestbook/</filename> is
more efficient and (from experience) less error-prone to set them to within your PHP include_path, then these settings are not necessary.
absolute paths. This ensures that Smarty is getting files from the However, it is more efficient and (from experience) less error-prone to
directories you intended. set them to absolute paths. This ensures that Smarty is getting files
from the directories you intended.
</para> </para>
</note> </note>
<para> <para>
Now load the index.php file from your web browser. You should see "Hello, Now load the <filename>index.php</filename> file from your web browser.
Ned!" You should see "Hello, Ned!"
</para> </para>
<para> <para>
You have completed the basic setup for Smarty! You have completed the basic setup for Smarty!
@@ -425,8 +434,9 @@ $smarty->display('index.tpl');
initialize your Smarty environment. So instead of repeatedly setting initialize your Smarty environment. So instead of repeatedly setting
directory paths, assigning the same vars, etc., we can do that in one place. directory paths, assigning the same vars, etc., we can do that in one place.
Lets create a new directory "/php/includes/guestbook/" and make a new file Lets create a new directory "/php/includes/guestbook/" and make a new file
called "setup.php". In our example environment, "/php/includes" is in our called <filename>setup.php</filename>. In our example environment,
include_path. Be sure you set this up too, or use absolute file paths. "/php/includes" is in our include_path. Be sure you set this up too, or
use absolute file paths.
</para> </para>
<example> <example>
@@ -448,14 +458,15 @@ class Smarty_GuestBook extends Smarty {
function Smarty_GuestBook() function Smarty_GuestBook()
{ {
// Class Constructor. These automatically get set with each new instance. // Class Constructor.
// These automatically get set with each new instance.
$this->Smarty(); $this->Smarty();
$this->template_dir = '/web/www.mydomain.com/smarty/guestbook/templates/'; $this->template_dir = '/web/www.example.com/smarty/guestbook/templates/';
$this->compile_dir = '/web/www.mydomain.com/smarty/guestbook/templates_c/'; $this->compile_dir = '/web/www.example.com/smarty/guestbook/templates_c/';
$this->config_dir = '/web/www.mydomain.com/smarty/guestbook/configs/'; $this->config_dir = '/web/www.example.com/smarty/guestbook/configs/';
$this->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/'; $this->cache_dir = '/web/www.example.com/smarty/guestbook/cache/';
$this->caching = true; $this->caching = true;
$this->assign('app_name', 'Guest Book'); $this->assign('app_name', 'Guest Book');
@@ -472,7 +483,7 @@ class Smarty_GuestBook extends Smarty {
</para> </para>
<example> <example>
<title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title> <title>Editing /web/www.example.com/docs/guestbook/index.php</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
@@ -491,7 +502,8 @@ $smarty->display('index.tpl');
<para> <para>
Now you see it is quite simple to bring up an instance of Smarty, just use Now you see it is quite simple to bring up an instance of Smarty, just use
Smarty_GuestBook which automatically initializes everything for our application. Smarty_GuestBook which automatically initializes everything for our
application.
</para> </para>
</sect1> </sect1>

View File

@@ -71,9 +71,13 @@ $smarty->assign_by_ref("myobj", $myobj);
$smarty->display("index.tpl"); $smarty->display("index.tpl");
?> ?>
]]>
TEMPLATE: </programlisting>
<para>
And here's how to access your objects in index.tpl:
</para>
<programlisting>
<![CDATA[
{* access our registered object *} {* access our registered object *}
{foobar->meth1 p1="foo" p2=$bar} {foobar->meth1 p1="foo" p2=$bar}

View File

@@ -29,12 +29,17 @@ function add_header_comment($tpl_source, &$smarty)
$smarty->register_postfilter("add_header_comment"); $smarty->register_postfilter("add_header_comment");
$smarty->display("index.tpl"); $smarty->display("index.tpl");
?> ?>
]]>
{* compiled Smarty template index.tpl *} </programlisting>
<para>
This will make the compiled Smarty template index.tpl look like:
</para>
<screen>
<![CDATA[
<!-- Created by Smarty! --> <!-- Created by Smarty! -->
{* rest of template content... *} {* rest of template content... *}
]]> ]]>
</programlisting> </screen>
</example> </example>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file

View File

@@ -6,12 +6,17 @@
Template prefilters are PHP functions that your templates are ran through Template prefilters are PHP functions that your templates are ran through
before they are compiled. This is good for preprocessing your templates before they are compiled. This is good for preprocessing your templates
to remove unwanted comments, keeping an eye on what people are putting to remove unwanted comments, keeping an eye on what people are putting
in their templates, etc. Prefilters can be either in their templates, etc.
<link linkend="api.register.prefilter">registered</link> or loaded from </para>
the plugins directory by using <para>
<link linkend="api.load.filter">load_filter()</link> function or by Prefilters can be either <link
setting linkend="api.register.prefilter">registered</link> or loaded from
<link linkend="variable.autoload.filters">$autoload_filters</link> variable. the plugins directory by using <link
linkend="api.load.filter">load_filter()</link> function or by setting
the <link linkend="variable.autoload.filters">$autoload_filters</link>
variable.
</para>
<para>
Smarty will pass the template source code as the first argument, and Smarty will pass the template source code as the first argument, and
expect the function to return the resulting template source code. expect the function to return the resulting template source code.
</para> </para>
@@ -30,11 +35,11 @@ function remove_dw_comments($tpl_source, &$smarty)
$smarty->register_prefilter("remove_dw_comments"); $smarty->register_prefilter("remove_dw_comments");
$smarty->display("index.tpl"); $smarty->display("index.tpl");
?> ?>
{* Smarty template index.tpl *}
<!--# this line will get removed by the prefilter -->
]]> ]]>
</programlisting> </programlisting>
<para>
This will remove all the comments in the template source.
</para>
</example> </example>
</sect1> </sect1>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file