Smarty (template engine)
Template:Short description Template:About
{{#invoke:Infobox|infobox}}Template:Template other {{#invoke:Check for unknown parameters|check|unknown=Template:Main other|preview=Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y| AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo class | logo size | logo title | logo upright | logo_alt | logo_caption | logo_class | logo_size | logo_title | logo_upright | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | qid | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot class | screenshot size | screenshot title | screenshot upright | screenshot_alt | screenshot_class | screenshot_size | screenshot_upright | service_name | size | standard | title | ver layout | website }}Template:Main other{{#invoke:Check for conflicting parameters|check | template = Template:Infobox software | cat = Template:Main other | logo size; logo_size | logo class; logo_class | logo alt; logo_alt | logo title; logo_title | logo caption; logo_caption | screenshot size; screenshot_size | screenshot upright; screenshot_upright | screenshot class; screenshot_class | screenshot alt; screenshot_alt | screenshot title; screenshot title | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | programming language; programming_language | operating system; operating_system }} Smarty is a web template system written in PHP. Smarty is primarily promoted as a tool for separation of concerns,[1] and is intended to simplify compartmentalization, allowing the front-end of a web page to change separately from its back-end. Ideally, this lowers costs and minimizes the efforts associated with software maintenance.
Smarty generates web content through 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, logical or loop statements. Smarty allows PHP programmers to define custom functions that can be accessed using Smarty tags.
Example
In this HTML file, { and } are the delimiters of Smarty tags. <syntaxhighlight lang="html+smarty"> <!DOCTYPE html> <html lang="en"> <head>
<meta charset="utf-8">
<title>{$title_text|escape}</title>
</head>
<body> {* This is a little comment that won't be visible in the HTML source *} {$body_html} </body> </html> </syntaxhighlight>
The PHP business logic to use the Smarty template above could be: <syntaxhighlight lang="php"> define('SMARTY_DIR', 'smarty-2.6.22/'); require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty(); $smarty->template_dir = './templates/'; $smarty->compile_dir = './templates/compile/';
$smarty->assign('title_text', 'TITLE: This is the Smarty basic example ...');
$smarty->assign('body_html', '
BODY: This is the message set using assign()
');
$smarty->display('index.tpl'); </syntaxhighlight>