Smarty (a PHP template engine)

[1] Introduction (ref. official site: )

Smarty is a template engine for PHP. More specifically, it facilitates a manageable way to separate application logic and content from its presentation.

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 easily create your own custom functions and variable modifiers, so the template language is extremely extensible.
• Configurable template {delimiter} tag syntax, so you can use {$foo}, {{$foo}}, <!–{$foo}–>, etc.
• The {if}..{elseif}..{else}..{/if} constructs are passed to the PHP parser, so the {if…} expression syntax can be as simple or as complex an evaluation as you like.
• Allows unlimited nesting of sections, if’s etc.
• 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

[2] Installation

Smarty tarball has been unpacked to:
/usr/local/lib/Smarty-v.e.r/ for *nix machines
d:\EasyPHP\php\Smarty-v.e.r\ for the windows enviroment.

ps. Add the library path to the php.ini file

; Paths and Directories ;
; *nix: “/path1:/path2”
include_path = “.:/usr/share/php:/usr/local/lib/Smarty-v.e.r/libs/”
; Windows: “\path1;\path2”
include_path = “.;d:\php\includes;d:\EasyPHP\php\Smarty-v.e.r\libs\”

ps. restart httpd

[3] File structure

/www/example/  (http://locahost/example/)

index.tpl (template file)
templates_c/   (make it be writable)
(make it be writable)
index.php  (php file)

ps. Permissions and making directories writable
chown nobody:nobody /web/
chmod 777 /web/
chown nobody:nobody /web/
chmod 777 /web/

ps. chmod 777 runs correctly. (original ref. is 770)

[4] Example



class Smarty_example extends Smarty{
public function __construct(){


$this->caching = true;



<!DOCTYPE HTML PUBLIC ‘-//W3C//DTD HTML 4.01 Transitional//EN’>
<meta http-equiv=’content-type’ content=’text/html; charset=UTF-8′>

<p>Output by <a href=’’>Smarty</a></p>


$smarty = new Smarty_example();


Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • MySpace
  • Plurk
  • RSS
  • Google Buzz
  • Live
本篇發表於 Smarty。將永久鏈結加入書籤。

Smarty (a PHP template engine) 有 1 則回應

  1. kristen stewart 說道:

    hi there great little blog ya have there 😉 I use the identical theme on my own website however for whatever weird factor it looks to stream faster on this blog despite the fact that this blog is carrying alot more content material. Are you currently utilizing any plugins or widgets which quicken it up? Do you think you could possibly show the programs so I can use these in my own webpage so twilight new moon users could watch twilight new moon online trailers and films easier I’d personally be ever so grateful – many thanks ahead of time 🙂


你的電子郵件位址並不會被公開。 必要欄位標記為 *