Tidied up formatting so more readable, tidied up the install to the paths are more clear (ta jj)

This commit is contained in:
pete_morgan
2006-10-09 22:07:53 +00:00
parent 0a9fa843fb
commit 3d66246282

View File

@@ -12,46 +12,88 @@
programmer and the template designer play different roles, or in most programmer and the template designer play different roles, or in most
cases are not the same person. cases are not the same person.
</para> </para>
<para> <para>
For example, let's say you are creating a web page that is displaying a For example, let's say you are creating a web page that is displaying a
newspaper article. The article headline, tagline, author and body are newspaper article.
</para>
<itemizedlist>
<listitem><para>
The article <literal>$headline</literal>, <literal>$tagline</literal>,
<literal>$author</literal> and <literal>$body</literal> are
content elements, they contain no information about how they will be content elements, they contain no information about how they will be
presented. They are passed into Smarty by the application, then the presented. They are <link linkend="api.assign">passed</link> into Smarty
by the application.
</para></listitem>
<listitem><para>Then the
template designer edits the templates and uses a combination of 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 <link linkend="language.basic.syntax">template tags</link>
(HTML tables, background colors, font sizes, style sheets, etc.) One day to format the presentation of these
the programmer needs to change the way the article content is retrieved (a <link linkend="language.syntax.variables">variables</link> with elements
change in application logic.) This change does not affect the template such as tables, div's, background colors, font sizes, style sheets, svg etc.
</para></listitem>
<listitem><para>One day
the programmer needs to change the way the article content is retrieved, ie a
change in application logic. This change does not affect the template
designer, the content will still arrive in the template exactly the same. designer, the content will still arrive in the template exactly the same.
</para></listitem>
<listitem><para>
Likewise, if the template designer wants to completely redesign the Likewise, if the template designer wants to completely redesign the
templates, this requires no changes to the application logic. Therefore, templates, this would require no change to the application logic.
</para></listitem>
<listitem><para>Therefore,
the programmer can make changes to the application logic without the need the programmer can make changes to the application logic without the need
to restructure templates, and the template designer can make changes to to restructure templates, and the template designer can make changes to
templates without breaking application logic. templates without breaking application logic.
</para> </para></listitem>
</itemizedlist>
<para> <para>
One design goal of Smarty is the separation of business logic and One design goal of Smarty is the separation of business logic and
presentation logic. This means templates can certainly contain logic under presentation logic.
the condition that it is for presentation only. Things such as including </para>
other templates, altering table row colors, upper-casing a variable,
looping over an array of data and displaying it, etc. are all examples of <itemizedlist>
presentation logic. This does not mean that Smarty forces a separation of <listitem><para>
This means templates can certainly contain logic under
the condition that it is for presentation only. Things such as
<link linkend="language.function.include">including</link>
other templates,
<link linkend="language.function.cycle">alternating</link> table row colors,
<link linkend="language.modifier.upper">upper-casing</link> a variable,
<link linkend="language.function.foreach">looping</link>
over an array of data and <link linkend="api.display">displaying</link> it
are examples of presentation logic.
</para></listitem>
<listitem><para>
This does not mean however 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.
</para></listitem>
<listitem><para>Also, if you
desire <emphasis>no</emphasis> logic in your templates you certainly can desire <emphasis>no</emphasis> logic in your templates you certainly can
do so by boiling the content down to text and variables only. do so by boiling the content down to text and variables only.
</para> </para></listitem>
</itemizedlist>
<para> <para>
One of the unique aspects about Smarty is the template compiling. This One of the unique aspects about Smarty is the template compiling. This
means Smarty reads the template files and creates PHP scripts from them. means Smarty reads the template files and creates PHP scripts from them.
Once they are created, they are executed from then on. Therefore there is Once they are created, they are executed from then on. Therefore there is
no costly template file parsing for each request, and each template can no costly template file parsing for each request. Each template can
take full advantage of PHP compiler cache solutions such as Zend take full advantage of PHP compiler and cache solutions such as
Accelerator (<ulink url="&url.zend;">&url.zend;</ulink>) or PHP Accelerator <ulink url="&url.e-accel;">eAccelerator</ulink>,
(<ulink url="&url.php-accelerator;">&url.php-accelerator;</ulink>). <ulink url="&url.ion-accel;">ionCube</ulink>
<ulink url="&url.mmcache-accel;">mmCache</ulink>
or <ulink url="&url.zend-accel;">Zend Accelerator</ulink>
to name a few.
</para> </para>
<para> <para>
Some of Smarty's features: <emphasis role="bold">Some of Smarty's features:</emphasis>
</para> </para>
<itemizedlist> <itemizedlist>
<listitem> <listitem>
@@ -71,40 +113,40 @@
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
It is smart about recompiling only the template files that have changed. It is smart about <link linkend="variable.compile.check">recompiling</link>
only the template files that have changed.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
You can make <link You can easily create your own custom <link
linkend="language.custom.functions">custom functions</link> linkend="language.custom.functions">functions</link>
and custom <link and <link linkend="language.modifiers">variable modifiers</link>, so the
linkend="language.modifiers">variable modifiers</link>, so the
template language is extremely extensible. template language is extremely extensible.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
Configurable template Configurable template
<link linkend="variable.left.delimiter">delimiter tag</link> <link linkend="variable.left.delimiter">{delimiter}</link> tag
syntax, so you can use syntax, so you can use
{}, {{}}, &lt;!--{}--&gt;, etc. <literal>{$foo}</literal>, <literal>{{$foo}}</literal>,
<literal>&lt;!--{$foo}--&gt;</literal>, etc.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
The <link The <link linkend="language.function.if">
linkend="language.function.if">if/elseif/else/endif</link> <literal>{if}..{elseif}..{else}..{/if}</literal></link>
constructs are passed to the constructs are passed to the
PHP parser, so the {if ...} expression syntax can be as simple or as PHP parser, so the <literal>{if...}</literal> expression syntax can be as
complex as you like. simple or as complex an evaluation as you like.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
Unlimited nesting of Allows unlimited nesting of <link linkend="language.function.section">
<link linkend="language.function.section">sections</link>, <varname>sections</varname></link>, <varname>if's</varname> etc.
ifs, etc. allowed.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
@@ -113,7 +155,7 @@
<link linkend="language.function.php">embed PHP code</link> <link linkend="language.function.php">embed PHP code</link>
right in your template files, although right in your template files, although
this may not be needed (nor recommended) since the engine is so this may not be needed (nor recommended) since the engine is so
customizable. <link linkend="plugins">customizable</link>.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
@@ -123,8 +165,7 @@
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
Arbitrary <link Arbitrary <link linkend="template.resources">template</link> sources
linkend="template.resources">template</link> sources
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
@@ -143,58 +184,77 @@
</chapter> </chapter>
<chapter id="installation"> <chapter id="installation">
<title>Installation</title> <title>Installation</title>
<sect1 id="installation.requirements"> <sect1 id="installation.requirements">
<title>Requirements</title> <title>Requirements</title>
<para> <para>
Smarty requires a web server running PHP 4.0.6 or later. Smarty requires a web server running PHP 4.0.6 or greater.
</para> </para>
</sect1> </sect1>
<sect1 id="installing.smarty.basic"> <sect1 id="installing.smarty.basic">
<title>Basic Installation</title> <title>Basic Installation</title>
<para> <para>
Install the Smarty library files which are in the <filename>/libs/</filename> Install the Smarty library files which are in the
sub directory of <filename class="directory">/libs/</filename> sub directory of
the distribution. These are PHP files that you SHOULD NOT edit. They the distribution. These are <filename>.php</filename> files that you
are shared among all applications and they only get updated when you SHOULD NOT edit. They are shared among all applications and only get
upgrade to a new version of Smarty. changed when you upgrade to a new version of Smarty.
</para> </para>
<para>In the examples below the Smarty tarball has been unpacked to:
<itemizedlist>
<listitem><para>
<filename class="directory">/usr/local/lib/Smarty-v.e.r/</filename> for *nix
machines</para></listitem>
<listitem><para> and
<filename class="directory">c:\webroot\libs\Smarty-v.e.r\</filename> for the
windows enviroment.</para></listitem>
</itemizedlist>
</para>
<example> <example>
<title>Required Smarty library files</title> <title>Required Smarty library files</title>
<screen> <screen>
<![CDATA[ <![CDATA[
Smarty.class.php Smarty-v.e.r/
Smarty_Compiler.class.php libs/
Config_File.class.php Smarty.class.php
debug.tpl Smarty_Compiler.class.php
/internals/*.php (all of them) Config_File.class.php
/plugins/*.php (all of them to be safe, maybe your site only needs a subset) debug.tpl
internals/*.php (all of them)
plugins/*.php (all of them)
]]> ]]>
</screen> </screen>
</example> </example>
<para> <para>
Smarty uses a PHP <ulink url="&url.php-manual;define">constant</ulink> named Smarty uses a PHP <ulink url="&url.php-manual;define">constant</ulink>
<link linkend="constant.smarty.dir"><constant>SMARTY_DIR</constant></link> which is the named <link linkend="constant.smarty.dir"><constant>SMARTY_DIR</constant>
<emphasis role="bold">full system file path</emphasis> to the Smarty </link> which is the <emphasis role="bold">full system file path</emphasis>
<filename>libs/</filename> directory. to the Smarty <filename>libs/</filename> directory.
Basically, if your application Basically, if your application can find the
can find the <filename>Smarty.class.php</filename> file, you do not need <filename>Smarty.class.php</filename> file, you do not need to set the
to set <link linkend="constant.smarty.dir"><constant>SMARTY_DIR</constant></link> <link linkend="constant.smarty.dir"><constant>SMARTY_DIR</constant></link>
as Smarty will figure it out on its own. Therefore, if as Smarty will figure it out on its own.
<filename>Smarty.class.php</filename> is not in your include_path, or you Therefore, if
do not supply an absolute path to it in your application, then you must <filename>Smarty.class.php</filename> is not in your
define <constant>SMARTY_DIR</constant> manually. <ulink url="&url.php-manual;ini.core.php#ini.include-path">include_path</ulink>,
or you do not supply an absolute path to it in your application,
then you must define <constant>SMARTY_DIR</constant> manually.
<constant>SMARTY_DIR</constant> <emphasis role="bold">must include a <constant>SMARTY_DIR</constant> <emphasis role="bold">must include a
trailing slash/</emphasis>. trailing slash/</emphasis>.
</para> </para>
<example> <informalexample>
<title>Create an instance of Smarty</title> <para>
<para>
Here's how you create an instance of Smarty in your PHP scripts: Here's how you create an instance of Smarty in your PHP scripts:
</para> </para>
<programlisting role="php"> <programlisting role="php">
@@ -206,11 +266,11 @@ $smarty = new Smarty();
?> ?>
]]> ]]>
</programlisting> </programlisting>
</example> </informalexample>
<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
<filename>Smarty.class.php</filename> file could not be found, you have to <filename>Smarty.class.php</filename> file could not be found, you need to
do one of the following: do one of the following:
</para> </para>
@@ -220,7 +280,7 @@ $smarty = new Smarty();
<![CDATA[ <![CDATA[
<?php <?php
// *nix style (note capital 'S') // *nix style (note capital 'S')
define('SMARTY_DIR', '/usr/local/lib/php/Smarty-v.e.r/libs/'); define('SMARTY_DIR', '/usr/local/lib/Smarty-v.e.r/libs/');
// windows style // windows style
define('SMARTY_DIR', 'c:/webroot/libs/Smarty-v.e.r/libs/'); define('SMARTY_DIR', 'c:/webroot/libs/Smarty-v.e.r/libs/');
@@ -242,7 +302,7 @@ $smarty = new Smarty();
<![CDATA[ <![CDATA[
<?php <?php
// *nix style (note capital 'S') // *nix style (note capital 'S')
require_once('/usr/local/lib/php/Smarty-v.e.r/libs/Smarty.class.php'); require_once('/usr/local/lib/Smarty-v.e.r/libs/Smarty.class.php');
// windows style // windows style
require_once('c:/webroot/libs/Smarty-v.e.r/libs/Smarty.class.php'); require_once('c:/webroot/libs/Smarty-v.e.r/libs/Smarty.class.php');
@@ -254,33 +314,52 @@ $smarty = new Smarty();
</example> </example>
<example> <example>
<title>Add library directory to PHP include_path</title> <title>Add the library path to the <filename>php.ini</filename> file</title>
<programlisting role="php">
<![CDATA[
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; *nix: "/path1:/path2"
include_path = ".:/usr/share/php:/usr/local/lib/Smarty-v.e.r/libs/"
; Windows: "\path1;\path2"
include_path = ".;c:\php\includes;c:\webroot\libs\Smarty-v.e.r\libs\"
]]>
</programlisting>
</example>
<example>
<title>Appending the include path in a php script with
<literal><ulink url="&url.e-accel;">ini_set()</ulink></literal></title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
// Edit your php.ini file, add the Smarty library // *nix
// directory to the include_path and restart web server. ini_set('include_path', ini_get('include_path').':/usr/local/lib/Smarty-v.e.r/libs/');
// then the following should work:
require_once('Smarty.class.php'); // windows
$smarty = new Smarty(); ini_set('include_path', ini_get('include_path').';c:/webroot/lib/Smarty-v.e.r/libs/');
?> ?>
]]> ]]>
</programlisting> </programlisting>
</example> </example>
<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.</para> directories for your application:</para>
<para>
<itemizedlist>
<listitem><para>
Smarty requires four directories which Smarty requires four directories which
are by default named <filename class="directory">'templates/'</filename>, are by default named <filename class="directory">templates/</filename>,
<filename class="directory">'templates_c/'</filename>, <filename <filename class="directory">templates_c/</filename>, <filename
class="directory">'configs/'</filename> and <filename class="directory">configs/</filename> and <filename
class="directory">'cache/'</filename>. class="directory">cache/</filename>
</para> </para></listitem>
<para>Each of these are definable by the
<listitem><para>Each of these are definable by the
Smarty class properties Smarty class properties
<link linkend="variable.template.dir"> <link linkend="variable.template.dir">
<varname>$template_dir</varname></link>, <varname>$template_dir</varname></link>,
@@ -289,103 +368,97 @@ $smarty = new Smarty();
<link linkend="variable.config.dir"> <link linkend="variable.config.dir">
<varname>$config_dir</varname></link>, and <varname>$config_dir</varname></link>, and
<link linkend="variable.cache.dir"> <link linkend="variable.cache.dir">
<varname>$cache_dir</varname></link> respectively. <varname>$cache_dir</varname></link> respectively
</para></listitem>
<listitem><para>
It is highly recommended 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></listitem>
<para> </itemizedlist>
Be sure you know the location of your web server document root. In our
examples, the document root is <filename <para>
class="directory">/web/www.example.com/docs/</filename>. The Smarty
directories are only accessed by the Smarty library and never accessed
directly by the web browser. Therefore to avoid any security concerns, it
is recommended to place these directories <emphasis>outside</emphasis> of
the document root.
</para>
<para>
For our installation example, we will be setting up the Smarty environment For our installation example, we will be setting up the Smarty environment
for a guest book application. We picked an application only for the purpose for a guest book application. We picked an application only for the purpose
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 <quote>guestbook</quote> with the name of your app. application, just replace <literal>guestbook/</literal> with
We'll place our Smarty directories under the name of your application.
<filename </para>
class="directory">/web/www.example.com/smarty/guestbook/</filename>.
</para>
<para>
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
<filename>index.php</filename>, and place it in a subdirectory under the
document root called <filename class="directory">/guestbook/</filename>.
</para>
<note>
<title>Technical Note</title>
<para>
It is convenient to setup the web server so that <filename>index.php</filename>
can be identified as the default directory index, so if you access
<literal>http://www.example.com/guestbook/</literal>, the <filename>index.php</filename>
script will be executed without adding <filename>index.php</filename> to
the URL. In Apache you can set this up by adding
<literal>index.php</literal> onto the end of your
<literal>DirectoryIndex</literal> setting (separate
each entry with a space) as in the following <filename>httpd.conf</filename> example.
<informalexample>
<programlisting>
<![CDATA[DirectoryIndex index.htm index.html index.cgi index.php]]>
</programlisting>
</informalexample>
</para>
</note>
<para>
Lets take a look at the file structure so far:
</para>
<example> <example>
<title>File structure so far</title> <title>What the file structure looks like</title>
<screen> <screen>
<![CDATA[ <![CDATA[
/usr/local/lib/php/Smarty-v.e.r/libs/Smarty.class.php /usr/local/lib/Smarty-v.e.r/libs/
/usr/local/lib/php/Smarty-v.e.r/libs/Smarty_Compiler.class.php Smarty.class.php
/usr/local/lib/php/Smarty-v.e.r/libs/Config_File.class.php Smarty_Compiler.class.php
/usr/local/lib/php/Smarty-v.e.r/libs/debug.tpl Config_File.class.php
/usr/local/lib/php/Smarty-v.e.r/libs/internals/*.php debug.tpl
/usr/local/lib/php/Smarty-v.e.r/libs/plugins/*.php internals/*.php
plugins/*.php
/web/www.example.com/smarty/guestbook/templates/ /web/www.example.com/
/web/www.example.com/smarty/guestbook/templates_c/ guestbook/
/web/www.example.com/smarty/guestbook/configs/ templates/
/web/www.example.com/smarty/guestbook/cache/ index.tpl
templates_c/
/web/www.example.com/docs/guestbook/index.php configs/
cache/
htdocs/
index.php
]]> ]]>
</screen> </screen>
</example> </example>
<para>
Be sure that you know the location of your web server's document root as a
file path. In the following examples, the document root is <filename
class="directory">/web/www.example.com/guestbook/htdocs/</filename>.
The Smarty
directories are only accessed by the Smarty library and never accessed
directly by the web browser. Therefore to avoid any security concerns, it
is recommended (but not mandatory) to place these directories
<emphasis>outside</emphasis> of the web server's document root.
</para>
<para>
You will need as least one file under your document root, and that is the
script accessed by the web browser. We will name our script
<filename>index.php</filename>, and place it in a subdirectory under the
document root <filename class="directory">/htdocs/</filename>.
</para>
<para> <para>
Smarty will need <emphasis role="bold">write access</emphasis> Smarty will need <emphasis role="bold">write access</emphasis>
(windows users please ignore) to the (windows users please ignore) to the
<link linkend="variable.compile.dir"> <link linkend="variable.compile.dir">
<parameter>$compile_dir</parameter></link> and <parameter>$compile_dir</parameter></link> and
<link linkend="variable.cache.dir"> <link linkend="variable.cache.dir">
<parameter>$cache_dir</parameter></link>, <parameter>$cache_dir</parameter></link> directories
so be sure the web server user can write (<filename class="directory">templates_c/</filename> and
to them. This is usually user "nobody" and group "nobody". For OS X users, <filename class="directory">cache/</filename>), so be sure the web server
the default is user "www" and group "www". If you are using Apache, you can user account can write to them.
look in your <filename>httpd.conf</filename> file to see
what user and group are being used. <note><para>This is usually user <quote>nobody</quote> and
</para> group <quote>nobody</quote>. For OS X users,
the default is user <quote>www</quote> and group <quote>www</quote>.
If you are using Apache, you can look in your
<filename>httpd.conf</filename> file to see
what user and group are being used.</para></note>
</para>
<example> <example>
<title>Setting file permissions</title> <title>Permissions and making directories writable</title>
<programlisting role="shell"> <programlisting role="shell">
<![CDATA[ <![CDATA[
chown nobody:nobody /web/www.example.com/smarty/guestbook/templates_c/ chown nobody:nobody /web/www.example.com/guestbook/templates_c/
chmod 770 /web/www.example.com/smarty/guestbook/templates_c/ chmod 770 /web/www.example.com/guestbook/templates_c/
chown nobody:nobody /web/www.example.com/smarty/guestbook/cache/ chown nobody:nobody /web/www.example.com/guestbook/cache/
chmod 770 /web/www.example.com/smarty/guestbook/cache/ chmod 770 /web/www.example.com/guestbook/cache/
]]> ]]>
</programlisting> </programlisting>
</example> </example>
@@ -393,21 +466,22 @@ chmod 770 /web/www.example.com/smarty/guestbook/cache/
<note> <note>
<title>Note</title> <title>Note</title>
<para> <para>
chmod 770 will be fairly tight security, it only allows user "nobody" and <literal>chmod 770</literal> will be fairly tight security, it only allows
group "nobody" read/write access to the directories. If you would like to user <quote>nobody</quote> and group <quote>nobody</quote> read/write access
open up read access to anyone (mostly for your own convenience of viewing to the directories. If you would like to open up read access to anyone
these files), you can use 775 instead. (mostly for your own convenience of viewing
these files), you can use <literal>775</literal> instead.
</para> </para>
</note> </note>
<para> <para>
We need to create the <filename>index.tpl</filename> file that Smarty will We need to create the <filename>index.tpl</filename> file that Smarty will
load. This needs to be located in the <link linkend="variable.template.dir"> display. This needs to be located in the <link linkend="variable.template.dir">
<parameter>$template_dir</parameter></link>. <parameter>$template_dir</parameter></link>.
</para> </para>
<example> <example>
<title>Our /web/www.example.com/smarty/guestbook/templates/index.tpl</title> <title>/web/www.example.com/guestbook/templates/index.tpl</title>
<screen> <screen>
<![CDATA[ <![CDATA[
{* Smarty *} {* Smarty *}
@@ -443,30 +517,30 @@ Hello {$name}, welcome to Smarty!
<![CDATA[ <![CDATA[
<?php <?php
// load Smarty library
require_once(SMARTY_DIR . 'Smarty.class.php'); require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty(); $smarty = new Smarty();
$smarty->template_dir = '/web/www.example.com/smarty/guestbook/templates/'; $smarty->template_dir = '/web/www.example.com/guestbook/templates/';
$smarty->compile_dir = '/web/www.example.com/smarty/guestbook/templates_c/'; $smarty->compile_dir = '/web/www.example.com/guestbook/templates_c/';
$smarty->config_dir = '/web/www.example.com/smarty/guestbook/configs/'; $smarty->config_dir = '/web/www.example.com/guestbook/configs/';
$smarty->cache_dir = '/web/www.example.com/smarty/guestbook/cache/'; $smarty->cache_dir = '/web/www.example.com/guestbook/cache/';
$smarty->assign('name','Ned'); $smarty->assign('name','Ned');
$smarty->display('index.tpl'); $smarty->display('index.tpl');
?> ?>
]]> ]]>
</programlisting> </programlisting>
</example> </example>
<note> <note>
<title>Technical Note</title> <title>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 <filename directories. If <filename
class="directory">/web/www.example.com/smarty/guestbook/</filename> is class="directory">/web/www.example.com/guestbook/</filename> is
within your PHP include_path, then these settings are not necessary. within your PHP include_path, then these settings are not necessary.
However, it is more efficient and (from experience) less error-prone to However, it is more efficient and (from experience) less error-prone to
set them to absolute paths. This ensures that Smarty is getting files set them to absolute paths. This ensures that Smarty is getting files
@@ -476,7 +550,7 @@ $smarty->display('index.tpl');
<para> <para>
Now naviagate to the <filename>index.php</filename> file with the web browser. Now naviagate to the <filename>index.php</filename> file with the web browser.
You should see "Hello Ned, welcome to Smarty!" You should see <emphasis>"Hello Ned, welcome to Smarty!"</emphasis>
</para> </para>
<para> <para>
You have completed the basic setup for Smarty! You have completed the basic setup for Smarty!
@@ -484,6 +558,9 @@ $smarty->display('index.tpl');
</sect1> </sect1>
<sect1 id="installing.smarty.extended"> <sect1 id="installing.smarty.extended">
<title>Extended Setup</title> <title>Extended Setup</title>
@@ -493,17 +570,22 @@ $smarty->display('index.tpl');
that first! that first!
</para> </para>
<para> <para>
A slightly more flexible way to setup Smarty is to extend the class and A slightly more flexible way to setup Smarty is to
<ulink url="&url.php-manual;ref.classobj">extend the class</ulink> and
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 <filename>/php/includes/guestbook/</filename> </para>
<para>
Lets create a new directory <filename
class="directory">/php/includes/guestbook/</filename>
and make a new file called <filename>setup.php</filename>. In our example and make a new file called <filename>setup.php</filename>. In our example
environment, <filename>/php/includes</filename> is in our include_path. environment, <filename class="directory">/php/includes</filename> is in our
<literal>include_path</literal>.
Be sure you set this up too, or use absolute file paths. Be sure you set this up too, or use absolute file paths.
</para> </para>
<example> <example>
<title>Editing /php/includes/guestbook/setup.php</title> <title>/php/includes/guestbook/setup.php</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php
@@ -526,10 +608,10 @@ class Smarty_GuestBook extends Smarty {
$this->Smarty(); $this->Smarty();
$this->template_dir = '/web/www.example.com/smarty/guestbook/templates/'; $this->template_dir = '/web/www.example.com/guestbook/templates/';
$this->compile_dir = '/web/www.example.com/smarty/guestbook/templates_c/'; $this->compile_dir = '/web/www.example.com/guestbook/templates_c/';
$this->config_dir = '/web/www.example.com/smarty/guestbook/configs/'; $this->config_dir = '/web/www.example.com/guestbook/configs/';
$this->cache_dir = '/web/www.example.com/smarty/guestbook/cache/'; $this->cache_dir = '/web/www.example.com/guestbook/cache/';
$this->caching = true; $this->caching = true;
$this->assign('app_name', 'Guest Book'); $this->assign('app_name', 'Guest Book');
@@ -542,11 +624,12 @@ class Smarty_GuestBook extends Smarty {
</example> </example>
<para> <para>
Now lets alter the <filename>index.php</filename> file to use <filename>setup.php</filename>: Now lets alter the <filename>index.php</filename> file to use
<filename>setup.php</filename>:
</para> </para>
<example> <example>
<title>Editing /web/www.example.com/docs/guestbook/index.php</title> <title>/web/www.example.com/guestbook/htdocs/index.php</title>
<programlisting role="php"> <programlisting role="php">
<![CDATA[ <![CDATA[
<?php <?php