diff --git a/docs/appendixes.sgml b/docs/appendixes.sgml
index 647f2084..93a2457d 100644
--- a/docs/appendixes.sgml
+++ b/docs/appendixes.sgml
@@ -1,119 +1,128 @@
Appendixes
-
- Troubleshooting
-
-
- Smarty/PHP errors
-
- Smarty can catch many errors such as missing tag attributes
- or malformed variable names. If this happens, you will see an error
- similar to the following:
-
-
-
-Smarty errors
-
+
+ Troubleshooting
+
+
+ Smarty/PHP errors
+
+ Smarty can catch many errors such as missing tag attributes
+ or malformed variable names. If this happens, you will see an error
+ similar to the following:
+
+
+ Smarty errors
+
+
-
-
-
- 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
- class that the error occured.
-
-
-
- There are certain errors that Smarty cannot catch, such as missing
- close tags. These types of errors usually end up in PHP compile-time
- parsing errors.
-
-
-
-PHP parsing errors
-
-Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
-
-
-
- When you encounter a PHP parsing error, the error line number will
- correspond to the compiled PHP script, not the template itself. Usually
- you can look at the template and spot the syntax error. Here are some
- common things to look for: missing close tags for {if}{/if} or
- {section}{/section}, or syntax of logic within an {if} tag. If you
- can't find the error, you might have to open the compiled PHP file and
- go to the line number to figure out where the corresponding error is in
- the template.
-
-
-
-
- Tips & Tricks
+ in /path/to/smarty/Smarty.class.php on line 1041
+]]>
+
+
+ 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
+ class that the error occured.
+
+
+
+ There are certain errors that Smarty cannot catch, such as missing
+ close tags. These types of errors usually end up in PHP compile-time
+ parsing errors.
-
- Blank Variable Handling
-
- There may be times when you want to print a default value for an empty
- variable instead of printing nothing, such as printing " " so that
- table backgrounds work properly. Many would use an {if} statement to
- handle this, but there is a shorthand way with Smarty, using the
- default variable modifier.
-
-
-Printing when a variable is empty
-
+
+ PHP parsing errors
+
+
+
+
+
+
+ When you encounter a PHP parsing error, the error line number will
+ correspond to the compiled PHP script, not the template itself. Usually
+ you can look at the template and spot the syntax error. Here are some
+ common things to look for: missing close tags for {if}{/if} or
+ {section}{/section}, or syntax of logic within an {if} tag. If you
+ can't find the error, you might have to open the compiled PHP file and
+ go to the line number to figure out where the corresponding error is in
+ the template.
+
+
+
+
+ Tips & Tricks
+
+
+
+ Blank Variable Handling
+
+ There may be times when you want to print a default value for an empty
+ variable instead of printing nothing, such as printing " " so that
+ table backgrounds work properly. Many would use an {if} statement to
+ handle this, but there is a shorthand way with Smarty, using the
+ default variable modifier.
+
+
+ Printing when a variable is empty
+
+
-
-
+{$title|default:" "}
+]]>
+
+
+
-
- Default Variable Handling
-
- If a variable is used frequently throughout your templates, applying
- the default modifier every time it is mentioned can get a bit ugly. You
- can remedy this by assigning the variable its default value with the
- assign function.
-
-
-Assigning a template variable its default value
-
+
+ Default Variable Handling
+
+ If a variable is used frequently throughout your templates, applying
+ the default modifier every time it is mentioned can get a bit ugly. You
+ can remedy this by assigning the variable its default value with the
+ assign function.
+
+
+ Assigning a template variable its default value
+
+
-
-
-
- Passing variable title to header template
-
- When the majority of your templates use the same headers and footers, it
- is common to split those out into their own templates and include them.
- But what if the header needs to have a different title, depending on
- what page you are coming from? You can pass the title to the header when
- it is included.
-
-
-Passing the title variable to the header template
-
-
+{$title}
+]]>
+
+
+
+
+ Passing variable title to header template
+
+ When the majority of your templates use the same headers and footers, it
+ is common to split those out into their own templates and include them.
+ But what if the header needs to have a different title, depending on
+ what page you are coming from? You can pass the title to the header when
+ it is included.
+
+
+ Passing the title variable to the header template
+
+
-
-
- 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
- archives page is drawn, the title will be "Archives". Notice in the
- archive example, we are using a variable from the archives_page.conf
- file instead of a hard coded variable. Also notice that "BC News" is
- printed if the $title variable is not set, using the
- default variable modifier.
-
-
-
- Dates
-
- As a rule of thumb, always pass dates to Smarty as timestamps. This
- allows template designers to use date_format for full
- control over date formatting, and also makes it easy to compare dates if
- necessary.
-
-
- NOTE: As of Smarty 1.4.0, you can pass dates to Smarty as unix
- timestamps, mysql timestamps, or any date parsable by strtotime().
-
-
-using date_format
-
+</HTML>
+]]>
+
+
+
+ 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
+ archives page is drawn, the title will be "Archives". Notice in the
+ archive example, we are using a variable from the archives_page.conf
+ file instead of a hard coded variable. Also notice that "BC News" is
+ printed if the $title variable is not set, using the
+ default variable modifier.
+
+
+
+ Dates
+
+ As a rule of thumb, always pass dates to Smarty as timestamps. This
+ allows template designers to use date_format for full
+ control over date formatting, and also makes it easy to compare dates if
+ necessary.
+
+
+ NOTE: As of Smarty 1.4.0, you can pass dates to Smarty as unix
+ timestamps, mysql timestamps, or any date parsable by strtotime().
+
+
+ using date_format
+
+
-
-
- 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.
-
-
-converting form date elements back to a timestamp
-
+ ...
+{/if}
+]]>
+
+
+
+ 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.
+
+
+ converting form date elements back to a timestamp
+
+
+
+
+
+
+ WAP/WML
+
+ WAP/WML templates require a php Content-Type header to be passed along
+ with the template. The easist way to do this would be to write a custom
+ function that prints the header. If you are using caching, that won't
+ work so we'll do it using the insert tag (remember insert tags are not
+ cached!) Be sure that there is nothing output to the browser before the
+ template, or else the header may fail.
+
+
+ using insert to write a WML Content-Type header
+
+
-
-
-
- WAP/WML
-
- WAP/WML templates require a php Content-Type header to be passed along
- with the template. The easist way to do this would be to write a custom
- function that prints the header. If you are using caching, that won't
- work so we'll do it using the insert tag (remember insert tags are not
- cached!) Be sure that there is nothing output to the browser before the
- template, or else the header may fail.
-
-
-using insert to write a WML Content-Type header
-
// 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) {
- // this function expects $content argument
- if(empty($params['content']))
- return;
- header($params['content']);
- return;
+ // this function expects $content argument
+ if(empty($params['content']))
+ return;
+ header($params['content']);
+ return;
}
-// your Smarty template _must_ begin with the insert tag example:
-
+?>
+]]>
+
+
+ your Smarty template must begin with the insert tag :
+
+
+
-
-
-
- Componentized Templates
-
- Traditionally, programming templates into your applications goes as
- follows: First, you accumulate your variables within your PHP
- application, (maybe with database queries.) Then, you instantiate your
- Smarty object, assign the variables and display the template. So lets
- say for example we have a stock ticker on our template. We would
- collect the stock data in our application, then assign these variables
- in the template and display it. Now wouldn't it be nice if you could
- add this stock ticker to any application by merely including the
- template, and not worry about fetching the data up front?
-
-
- You can do this by writing a custom plugin for fetching the content and
- assigning it to a template variable.
-
-
-componentized template
-
-function.load_ticker.php
----------------
+</wml>
+]]>
+
+
+
+
+ Componentized Templates
+
+ Traditionally, programming templates into your applications goes as
+ follows: First, you accumulate your variables within your PHP
+ application, (maybe with database queries.) Then, you instantiate your
+ Smarty object, assign the variables and display the template. So lets
+ say for example we have a stock ticker on our template. We would
+ collect the stock data in our application, then assign these variables
+ in the template and display it. Now wouldn't it be nice if you could
+ add this stock ticker to any application by merely including the
+ template, and not worry about fetching the data up front?
+
+
+ You can do this by writing a custom plugin for fetching the content and
+ assigning it to a template variable.
+
+
+ componentized template
+
+assign($params['assign'],$ticker_info);
+ // call the function
+ $ticker_info = fetch_ticker("YHOO",$ticker_info);
+
+ // assign template variable
+ $smarty->assign($params['assign'],$ticker_info);
}
-?>
-
+?>
+]]>
+
+
+
-
-
-
- Obfuscating E-mail Addresses
-
- Do you ever wonder how your E-mail address gets on so many spam mailing
- lists? One way spammers collect E-mail addresses is from web pages. To
- help combat this problem, you can make your E-mail address show up in
- scrambled javascript in the HTML source, yet it it will look and work
- correctly in the browser. This is done with the mailto plugin.
-
-
-Example of Obfuscating an E-mail Address
-
-
+Stock Name: {$ticker.name} Stock Price: {$ticker.price}
+]]>
+
+
+
+
+ Obfuscating E-mail Addresses
+
+ Do you ever wonder how your E-mail address gets on so many spam mailing
+ lists? One way spammers collect E-mail addresses is from web pages. To
+ help combat this problem, you can make your E-mail address show up in
+ scrambled javascript in the HTML source, yet it it will look and work
+ correctly in the browser. This is done with the mailto plugin.
+
+
+ Example of Obfuscating an E-mail Address
+
+
-
-
- Technical Note
-
- This method isn't 100% foolproof. A spammer could conceivably program his
- e-mail collector to decode these values, but not likely.
-
-
-
-
-
- Resources
-
- Smarty's homepage is located at http://smarty.php.net/.
- You can join the mailing list by sending an e-mail to
- smarty-general-subscribe@lists.php.net. An archive of the mailing list can be
- viewed at http://marc.theaimsgroup.com/?l=smarty&r=1&w=2
-
-
-
- BUGS
-
- Check the BUGS file that comes with the latest distribution of Smarty, or
- check the website.
-
-
+]]>
+
+
+
+ Technical Note
+
+ This method isn't 100% foolproof. A spammer could conceivably program his
+ e-mail collector to decode these values, but not likely.
+
+
+
+
+
+ Resources
+
+ Smarty's homepage is located at http://smarty.php.net/.
+ You can join the mailing list by sending an e-mail to
+ smarty-general-subscribe@lists.php.net. An archive of the mailing list can be
+ viewed at http://marc.theaimsgroup.com/?l=smarty&r=1&w=2
+
+
+
+ BUGS
+
+ Check the BUGS file that comes with the latest distribution of Smarty, or
+ check the website.
+
+
diff --git a/docs/getting-started.sgml b/docs/getting-started.sgml
index 1a598539..f41a43bc 100644
--- a/docs/getting-started.sgml
+++ b/docs/getting-started.sgml
@@ -2,76 +2,126 @@
Getting Started
- What is Smarty?
-
- Smarty is a template engine for PHP. More specifically, it facilitates a
- manageable way to separate application logic and content from its
- presentation. This is best described in a situation where the application
- programmer and the template designer play different roles, or in most cases
- are not the same person. 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 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 tables, background colors, font sizes, style sheets, etc.) One day
- the programmer needs to change the way the article content is retrieved (a
- change in application logic.) This change does not affect the template
- designer, the content will still arrive in the template exactly the same.
- Likewise, if the template designer wants to completely redesign the
- templates, this requires no changes to the application logic. Therefore,
- the programmer can make changes to the application logic without the need
- to restructure templates, and the template designer can make changes to
- templates without breaking application logic.
-
-
- One design goal of Smarty is the separation of business logic and
- presentation logic. This means templates can certainly contain logic under
- the condition that it is for presentation only. Things such as including
- other templates, altering table row colors, upper-casing a variable,
- looping over an array of data and displaying it, etc. are all examples 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,
- 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
- content down to text and variables only.
-
-
- One of the unique aspects about Smarty is the template compling. This 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 no
- costly template file parsing for each request, and each template can take
- full advantage of PHP compiler cache solutions such as Zend Accelerator
- (http://www.zend.com) or PHP Accelerator
- (http://www.php-accelerator.co.uk).
-
-
- Some of Smarty's features:
-
-
- It is extremely fast.
- It is efficient since the PHP parser does the
- dirty work.
- No template parsing overhead, only compiles once.
- It is smart about recompiling only the template
- files that have changed.
- You can make custom
- functions and custom variable
- modifiers, so the template language is extremely extensible.
- Configurable template delimiter tag syntax, so you can use
- {}, {{}}, <!--{}-->, etc.
- 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.
- Unlimited nesting of sections, ifs, etc. allowed.
- 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.
- Built-in caching support
- Arbitrary template sources
- Custom cache handling functions
- Plugin architecture
-
+ What is Smarty?
+
+ Smarty is a template engine for PHP. More specifically, it facilitates a
+ manageable way to separate application logic and content from its
+ presentation. This is best described in a situation where the application
+ programmer and the template designer play different roles, or in most cases
+ are not the same person. 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 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 tables, background colors, font sizes, style sheets, etc.) One day
+ the programmer needs to change the way the article content is retrieved (a
+ change in application logic.) This change does not affect the template
+ designer, the content will still arrive in the template exactly the same.
+ Likewise, if the template designer wants to completely redesign the
+ templates, this requires no changes to the application logic. Therefore,
+ the programmer can make changes to the application logic without the need
+ to restructure templates, and the template designer can make changes to
+ templates without breaking application logic.
+
+
+ One design goal of Smarty is the separation of business logic and
+ presentation logic. This means templates can certainly contain logic under
+ the condition that it is for presentation only. Things such as including
+ other templates, altering table row colors, upper-casing a variable,
+ looping over an array of data and displaying it, etc. are all examples 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,
+ 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
+ content down to text and variables only.
+
+
+ One of the unique aspects about Smarty is the template compling. This 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 no
+ costly template file parsing for each request, and each template can take
+ full advantage of PHP compiler cache solutions such as Zend Accelerator
+ (http://www.zend.com) or PHP Accelerator
+ (http://www.php-accelerator.co.uk).
+
+
+ Some of Smarty's features:
+
+
+
+
+ It is extremely fast.
+
+
+
+
+ It is efficient since the PHP parser does the dirty work.
+
+
+
+
+ No template parsing overhead, only compiles once.
+
+
+
+
+ It is smart about recompiling only the template files that have changed.
+
+
+
+
+ You can make custom functions
+ and custom variable modifiers, so the
+ template language is extremely extensible.
+
+
+
+
+ Configurable template delimiter tag syntax, so you can use
+ {}, {{}}, <!--{}-->, etc.
+
+
+
+
+ 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.
+
+
+
+
+ Unlimited nesting of sections, ifs, etc. allowed.
+
+
+
+
+ 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.
+
+
+
+
+ Built-in caching support
+
+
+
+
+ Arbitrary template sources
+
+
+
+
+ Custom cache handling functions
+
+
+
+
+ Plugin architecture
+
+
+ Installation
@@ -79,136 +129,159 @@
Requirements
- Smarty requires a web server running PHP 4.0.6 or later.
+ Smarty requires a web server running PHP 4.0.6 or later.
- Basic Installation
-
- Install the Smarty library files which are in the /libs/ directory of
- the distribution. These are the PHP files that you SHOULD NOT edit. They
- are shared among all applications and they only get updated when you
- upgrade to a new version of Smarty.
-
-
- Smarty library files
-
+ Basic Installation
+
+ Install the Smarty library files which are in the /libs/ directory of
+ the distribution. These are the PHP files that you SHOULD NOT edit. They
+ are shared among all applications and they only get updated when you
+ upgrade to a new version of Smarty.
+
+
+ Smarty library files
+
+
-
-
-
- Smarty uses a PHP constant named SMARTY_DIR which is the system
- filepath Smarty library directory. Basically, if your application can find
- the Smarty.class.php file, you do not need to set
- SMARTY_DIR, Smarty will figure it out on its own. Therefore, if
- Smarty.class.php is not in your include_path, or you
- do not supply an absolute path to it in your application, then you must
- define SMARTY_DIR manually. SMARTY_DIR must include a
- trailing slash.
-
-
- Here is how you create an instance of Smarty in your PHP scripts:
-
-
-
- Create Smarty instance of Smarty
-
+/plugins/*.php (all of them)
+]]>
+
+
+
+ Smarty uses a PHP constant named SMARTY_DIR which is the system
+ filepath Smarty library directory. Basically, if your application can find
+ the Smarty.class.php file, you do not need to set
+ SMARTY_DIR, Smarty will figure it out on its own. Therefore, if
+ Smarty.class.php is not in your include_path, or you
+ do not supply an absolute path to it in your application, then you must
+ define SMARTY_DIR manually. SMARTY_DIR must include a
+ trailing slash.
+
+
+ Here is how you create an instance of Smarty in your PHP scripts:
+
+
+
+ Create Smarty instance of Smarty
+
+
-
+$smarty = new Smarty;
+?>
+]]>
+
+
-
- Try running the above script. If you get an error saying the
- Smarty.class.php file could not be found, you have to
- do one of the following:
-
+
+ Try running the above script. If you get an error saying the
+ Smarty.class.php file could not be found, you have to
+ do one of the following:
+
-
- Supply absolute path to library file
-
+
+ Supply absolute path to library file
+
+
-
+$smarty = new Smarty;
+?>
+]]>
+
+
-
- Add library directory to php_include path
-
+
+ Add library directory to php_include path
+
+
-
+$smarty = new Smarty;
+?>
+]]>
+
+
-
- Set SMARTY_DIR constant manually
-
-define('SMARTY_DIR','/usr/local/lib/php/Smarty/');
-require(SMARTY_DIR.'Smarty.class.php');
-$smarty = new Smarty;
-
+
+ Set SMARTY_DIR constant manually
+
+
+]]>
+
+
-
- Now that the library files are in place, it's time to setup the Smarty
- directories for your application. Smarty requires four directories which
- are (by default) named templates,
- templates_c, configs and
- cache. Each of these are definable by the Smarty class
- properties $template_dir,
- $compile_dir, $config_dir, and
- $cache_dir respectively. It is highly recommended
- that you setup a separate set of these directories for each application
- that will use Smarty.
-
-
- 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
- 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 outside of
- the document root.
-
-
- 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
- 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
- place our Smarty directories under
- "/web/www.mydomain.com/smarty/guestbook/".
-
-
- 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",
- and place it in a subdirectory under the document root called
- "/guestbook/".
-
-
-
- Technical Note
-
- It is convenient to setup the web server so that "index.php" can be
- identified as the default directory index, so if you access
- "http://www.mydomain.com/guestbook/", the index.php script will be executed
- 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
- entry with a space.)
-
-
-
-
- Lets take a look at the file structure so far:
-
+
+ Now that the library files are in place, it's time to setup the Smarty
+ directories for your application. Smarty requires four directories which
+ are (by default) named templates,
+ templates_c, configs and
+ cache. Each of these are definable by the Smarty class
+ properties $template_dir,
+ $compile_dir, $config_dir, and
+ $cache_dir respectively. It is highly recommended
+ that you setup a separate set of these directories for each application
+ that will use Smarty.
+
+
+ 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
+ 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 outside of
+ the document root.
+
+
+ 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
+ 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
+ place our Smarty directories under
+ "/web/www.mydomain.com/smarty/guestbook/".
+
+
+ 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",
+ and place it in a subdirectory under the document root called
+ "/guestbook/".
+
+
+
+ Technical Note
+
+ It is convenient to setup the web server so that "index.php" can be
+ identified as the default directory index, so if you access
+ "http://www.mydomain.com/guestbook/", the index.php script will be executed
+ 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
+ entry with a space.)
+
+
+
+
+ Lets take a look at the file structure so far:
+
-
- Example file structure
-
+
+ Example file structure
+
+
/web/www.mydomain.com/smarty/guestbook/configs/
/web/www.mydomain.com/smarty/guestbook/cache/
-/web/www.mydomain.com/docs/guestbook/index.php
-
+/web/www.mydomain.com/docs/guestbook/index.php
+]]>
+
+
-
- Smarty will need write access to the $compile_dir and
- $cache_dir, so be sure the web server user can write
- to them. This is usually user "nobody" and group "nobody". For OS X users,
- the default is user "www" and group "www". If you are using Apache, you can
- look in your httpd.conf file (usually in "/usr/local/apache/conf/") to see
- what user and group are being used.
-
-
-
- Setting file permissions
-
+
+ Smarty will need write access to the $compile_dir and
+ $cache_dir, so be sure the web server user can write
+ to them. This is usually user "nobody" and group "nobody". For OS X users,
+ the default is user "www" and group "www". If you are using Apache, you can
+ look in your httpd.conf file (usually in "/usr/local/apache/conf/") to see
+ what user and group are being used.
+
+
+ Setting file permissions
+
+
-
+chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/
+]]>
+
+
-
- Technical Note
-
- chmod 770 will be fairly tight security, it only allows user "nobody" and
- group "nobody" read/write access to the directories. If you would like to
- open up read access to anyone (mostly for your own convenience of viewing
- these files), you can use 775 instead.
-
-
+
+ Technical Note
+
+ chmod 770 will be fairly tight security, it only allows user "nobody" and
+ group "nobody" read/write access to the directories. If you would like to
+ open up read access to anyone (mostly for your own convenience of viewing
+ these files), you can use 775 instead.
+
+
-
- We need to create the index.tpl file that Smarty will load. This will be
- located in your $template_dir.
-
+
+ We need to create the index.tpl file that Smarty will load. This will be
+ located in your $template_dir.
+
-
- Editing /web/www.mydomain.com/smarty/guestbook/templates/index.tpl
-
+
+ Editing /web/www.mydomain.com/smarty/guestbook/templates/index.tpl
+
+
-
+Hello, {$name}!
+]]>
+
+
+
+ Technical Note
+
+ {* Smarty *} is a template comment. It is not required, but it is good
+ practice to start all your template files with this comment. It makes
+ the file easy to recognize regardless of the file extension. For
+ example, text editors could recognize the file and turn on special
+ syntax highlighting.
+
+
-
- Technical Note
-
- {* Smarty *} is a template comment. It is not required, but it is good
- practice to start all your template files with this comment. It makes
- the file easy to recognize regardless of the file extension. For
- example, text editors could recognize the file and turn on special
- syntax highlighting.
-
-
+
+ Now lets edit index.php. We'll create an instance of Smarty, assign a
+ template variable and display the index.tpl file. In our example
+ environment, "/usr/local/lib/php/Smarty" is in our include_path. Be sure you
+ do the same, or use absolute paths.
+
-
- Now lets edit index.php. We'll create an instance of Smarty, assign a
- template variable and display the index.tpl file. In our example
- environment, "/usr/local/lib/php/Smarty" is in our include_path. Be sure you
- do the same, or use absolute paths.
-
+
+ Editing /web/www.mydomain.com/docs/guestbook/index.php
+
+
- Editing /web/www.mydomain.com/docs/guestbook/index.php
-
// load Smarty library
require('Smarty.class.php');
@@ -302,49 +384,54 @@ $smarty->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/';
$smarty->assign('name','Ned');
-$smarty->display('index.tpl');
-
+$smarty->display('index.tpl');
+?>
+]]>
+
+
-
- Technical Note
-
- In our example, we are setting absolute paths to all of the Smarty
- directories. If '/web/www.mydomain.com/smarty/guestbook/' is within your
- PHP include_path, then these settings are not necessary. However, it is
- more efficient and (from experience) less error-prone to set them to
- absolute paths. This ensures that Smarty is getting files from the
- directories you intended.
-
-
+
+ Technical Note
+
+ In our example, we are setting absolute paths to all of the Smarty
+ directories. If '/web/www.mydomain.com/smarty/guestbook/' is within your
+ PHP include_path, then these settings are not necessary. However, it is
+ more efficient and (from experience) less error-prone to set them to
+ absolute paths. This ensures that Smarty is getting files from the
+ directories you intended.
+
+
-
- Now load the index.php file from your web browser. You should see "Hello,
- Ned!"
-
-
- You have completed the basic setup for Smarty!
-
-
-
+
+ Now load the index.php file from your web browser. You should see "Hello,
+ Ned!"
+
+
+ You have completed the basic setup for Smarty!
+
+
+ Extended Setup
- This is a continuation of the basic installation, please read
- that first!
+ This is a continuation of the basic installation, please read
+ that first!
- A slightly more flexible way to setup Smarty is to extend the class and
- initialize your Smarty environment. So instead of repeatedly setting
- 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
- called "setup.php". In our example environment, "/php/includes" is in our
- include_path. Be sure you set this up too, or use absolute file paths.
+ A slightly more flexible way to setup Smarty is to extend the class and
+ initialize your Smarty environment. So instead of repeatedly setting
+ 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
+ called "setup.php". In our example environment, "/php/includes" is in our
+ include_path. Be sure you set this up too, or use absolute file paths.
Editing /php/includes/guestbook/setup.php
-
+
+Smarty();
+ $this->Smarty();
- $this->template_dir = '/web/www.mydomain.com/smarty/guestbook/templates/';
- $this->compile_dir = '/web/www.mydomain.com/smarty/guestbook/templates_c/';
- $this->config_dir = '/web/www.mydomain.com/smarty/guestbook/configs/';
- $this->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/';
-
- $this->caching = true;
- $this->assign('app_name','Guest Book');
+ $this->template_dir = '/web/www.mydomain.com/smarty/guestbook/templates/';
+ $this->compile_dir = '/web/www.mydomain.com/smarty/guestbook/templates_c/';
+ $this->config_dir = '/web/www.mydomain.com/smarty/guestbook/configs/';
+ $this->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/';
+
+ $this->caching = true;
+ $this->assign('app_name','Guest Book');
}
-}
+}
+?>
+]]>
+
- Now lets alter the index.php file to use setup.php:
+ Now lets alter the index.php file to use setup.php:
-
- Editing /web/www.mydomain.com/docs/guestbook/index.php
-
+
+ Editing /web/www.mydomain.com/docs/guestbook/index.php
+
+assign('name','Ned');
-$smarty->display('index.tpl');
-
+$smarty->display('index.tpl');
+?>
+]]>
+
+
- 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.
+ 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.