Smarty

Smarty

Infobox Software
name = Smarty Templates

developer = Monte Ohrt, Messju Mohr
latest_release_version = 2.6.20
latest_release_date = 15th Aug 2008
genre = Template Engine
license = LGPL
website = [http://www.smarty.net/ www.smarty.net]

Smarty is a web template system written in PHP. Smarty is primarily promoted as a tool for separation of concerns, which is a common design strategy for certain kinds of applications. [Smarty separates PHP code, (often represented as business logic) from HTML, (often represented as presentation logic).] cite book
first = Terence John
last = Parr
title = Enforcing strict model-view separation in template engines
publisher = Proceedings of the 13th international conference on World Wide Web
year = 2004
id = 1-58113-844-X
]

Smarty generates web content by the placement of special "Smarty tags" within a document. These tags are processed and substituted with other code.

Tags are directives for Smarty that are enclosed by template delimiters. These directives can be variables, denoted by a dollar sign ($), functions, or logical or control flow statements. Smarty allows PHP programmers to define functions that can be accessed using Smarty tags.

Smarty is intended to simplify compartmentalization, allowing the presentation of a web page to change separately from the back-end. Ideally, this eases the costs and efforts associated with software maintenance. Under successful application of this development strategy, designers are shielded from the back-end coding, and PHP programmers are shielded from the presentation coding.

Smarty supports several high-level template programming features, including:

* Control flow statements, foreach
* if, elseif, else
* variable modifiers - For example {$variable|nl2br}
* user created functions
* mathematical evaluation within the template

along with other features. There are other template engines that also support these features. Smarty templates are often incorporated into existing PHP web applications to some extent. More often it is used where a web application or a website has a theme system built into it, where the templates can be changed from theme to theme.

Code example

Since Smarty separates PHP from HTML, you have two files:

{$title_text}

{* This is a little comment that won't be visible in the HTML source *}

{$body_text}

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->template_dir = './templates/';$smarty->compile_dir = './templates/compile/';$smarty->cache_dir = './templates/cache/';$smarty->caching = false;$smarty->error_reporting = E_ALL; // LEAVE E_ALL DURING DEVELOPMENT$smarty->debugging = true;

$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('index.tpl');

Notes and references

External links

* [http://www.smarty.net Official site]
* [http://devzone.zend.com/article/1238-PHP-Templating-with-Smarty "PHP Templating with Smarty"] by Cezar Floroiu - Smarty tutorial
* [http://www.devpapers.com/article/18 "Smarty vs. XML/XSLT"] - from DevPapers.com by Sergey Makogon
* [http://hasin.wordpress.com/2006/06/10/smarty-cheat-sheet-version-20/ Smarty Cheat Sheet] Smarty Cheat Sheet for Templates Designers and Programmers
* [http://www.timestretch.com/php_intro/?page=smarty Timestretch: "PHP, MySQL, and Smarty Programming"] - Also see the PHP2 page for more.


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Smarty — Entwickler Monte Ohrt, Messju Mohr Aktuelle Version 3.1.4 (19. Oktober 2011) Betriebssystem plattformunabhängig Programmier­sprache PHP …   Deutsch Wikipedia

  • Smarty — Тип Компилирующий обработчик шаблонов Разработчик New Digital Group, Inc …   Википедия

  • Smarty — Desarrollador Monte Ohrt, Messju Mohr http://www.smarty.net/ Información general Última versión estable 3.1.4 ( …   Wikipedia Español

  • Smarty — es un motor de plantillas para PHP, cuyo objetivo es separar el contenido de la presentación en una página web, se encuentra bajo la licencia GPL por lo que puede ser usado libremente. Es común que en grandes proyectos el rol de diseñador gráfico …   Enciclopedia Universal

  • smarty — ☆ smarty [smart′ēpants΄smart′ē ] n. pl. smarties Informal SMART ALECK: also smarty pants [smart′ēpants΄] …   English World dictionary

  • Smarty — Pour les articles homonymes, voir Smarty (homonymie). Développeur Monte Ohrt, Messju Mohr …   Wikipédia en Français

  • smarty —    Used mainly in the USA to someone who is ostentatiously displaying smartness, especially if he is doing so by contradicting the speaker. ‘Smarty’ is a relatively mild term. An American who is more irate is likely to use: smart aleck, smartass …   A dictionary of epithets and terms of address

  • smarty — n. a cocky person. (Also a term of address.) □ Well, if you’re such a smarty, why aren’t you rich? □ Okay, smarty, do it yourself …   Dictionary of American slang and colloquial expressions

  • smarty — n. (pl. ies) colloq. 1 a know all; a smart alec. 2 a smartly dressed person; a member of a smart set. Phrases and idioms: smarty boots (or pants) = SMARTY 1. Etymology: SMART …   Useful english dictionary

  • smarty — Synonyms and related words: boldface, brazenface, chutzpanik, hussy, know it all, malapert, minx, pup, puppy, saucebox, smart, smart aleck, smart ass, smarty pants, swaggerer, upstart, whippersnapper, wise guy, wise ass, wiseacre, wisecracker,… …   Moby Thesaurus

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”