Smarty
Encyclopedia : S : SM : SMA : Smarty
- For the candies of the same name, please see Smarties
Smarty is a template engine written in PHP. Smarty separates PHP from HTML and is primarily used for the generation of dynamic HTML content, by allowing for the placement of special Smarty tags within a document. Allowable tags include, but are not limited to, variables such as , and a range of logical and loop operators.
Smarty is most often used by PHP-based applications to separate "business logic" from presentation. This makes for much cleaner coding and more flexible modification. For instance, one could typically modify a Smarty-based application's appearance (or, skin) easily, without ever looking at any business logic or PHP code.
Smarty allows template programming with
- regular expressions
- foreach
- if
- nl2br
Code example
Since Smarty separates PHP from HTML, you have two files:
<!-- this is a little comment that will be seen in source -->
In the business logic code you can configure Smarty to use this template:
define('SMARTY_DIR', 'smarty-2.6.9/' );
require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty;
$smarty->config_dir = SMARTY_DIR;
$smarty->template_dir = './tmpl';
$smarty->compile_dir = './tmpl/compile';
$smarty->compile_check = TRUE;
$smarty->debugging = FALSE;
$smarty->assign('title_text', 'TITLE: This is the Smarty basic example ...');
$smarty->assign('body_text', 'BODY: This is the message set using assign()');
$smarty->display('basic.htm');
Software built with Smarty
- Bitweaver
- last.fm
- bBlog
- Gallery
- Ozone PHP Framework
- TikiWiki
- XOOPS
- paFileDB
- ATK - Achievo ToolKit
- Zoop Framework for PHP
- [Supersite]
- CMScout
- Flickr
- [Trybes by Accepté (Netherlands)]
- Geograph
- [Zephyr Framework]The AJAXed MVC Framework for PHP5 Developers
See also
- PRADO, a component-based web development framework for PHP5
- CakePHP, a PHP web application framework inspired by Ruby on Rails
- PHROOT, PHP Rapid Object Oriented Technology Framework Project
External links
- [Smarty Home Page] - official site.
- [Download]
- [Smarty Resources list]
- [Forum] - [other languages]
- [Smarty users knowledge base Wiki]
- [PHP Templating with Smarty] by Cezar Floroiu - Smarty tutorial
- [Smarty vs. XML/XSLT] - from DevPapers.com by Sergey Makogon
- Article "[Templates, Gift from Heaven or Syntactic Junk Food?]" by Nathan Oostendorp
- [Chapter] from Smarty PHP Template Programming and Applications book.
- [Smarty Cheat Sheet] Smarty Cheat Sheet for Templates Designers and Programmers
- CakePHP
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
