A Web template system describes the software and methodologies used to produce web pages and for deployment on websites and delivery over the Internet.... written in PHP
PHP
PHP is a scripting language originally designed for producing dynamic web pages. It has evolved to include a command line interface capability and can be used in Standalone software Graphical user interface.... . Smarty is primarily promoted as a tool for separation of concerns
Separation of concerns
In computer science, separation of concerns is the process of breaking a computer program into distinct features that overlap in functionality as little as possible.... , which is a common design strategy for certain kinds of applications.
Smarty generates web content by the placement of special Smarty tags within a document. These tags are processed and substituted
Variable
A variable is a symbol that stands for a value that may vary; the term usually occurs in opposition to constant, which is a symbol for a non-varying value, i.e.... with other code.
A delimiter is a sequence of one or more character s used to specify the boundary between separate, independent regions in plain text or other data stream.... . These directives can be variables
Variable
A variable is a symbol that stands for a value that may vary; the term usually occurs in opposition to constant, which is a symbol for a non-varying value, i.e.... , denoted by a dollar sign ($), functions, logical
Conditional statement
In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified condition evaluates to true or false .... or loop
Control flow
In computer science control flow refers to the order in which the individual statement , Instruction or function calls of an imperative programming or functional programming computer program are execution or evaluated.... statements.
A Web template system describes the software and methodologies used to produce web pages and for deployment on websites and delivery over the Internet.... written in PHP
PHP
PHP is a scripting language originally designed for producing dynamic web pages. It has evolved to include a command line interface capability and can be used in Standalone software Graphical user interface.... . Smarty is primarily promoted as a tool for separation of concerns
Separation of concerns
In computer science, separation of concerns is the process of breaking a computer program into distinct features that overlap in functionality as little as possible.... , which is a common design strategy for certain kinds of applications.
Smarty generates web content by the placement of special Smarty tags within a document. These tags are processed and substituted
Variable
A variable is a symbol that stands for a value that may vary; the term usually occurs in opposition to constant, which is a symbol for a non-varying value, i.e.... with other code.
A delimiter is a sequence of one or more character s used to specify the boundary between separate, independent regions in plain text or other data stream.... . These directives can be variables
Variable
A variable is a symbol that stands for a value that may vary; the term usually occurs in opposition to constant, which is a symbol for a non-varying value, i.e.... , denoted by a dollar sign ($), functions, logical
Conditional statement
In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified condition evaluates to true or false .... or loop
Control flow
In computer science control flow refers to the order in which the individual statement , Instruction or function calls of an imperative programming or functional programming computer program are execution or evaluated.... statements. Smarty allows PHP programmers to define custom functions that can be accessed using Smarty tags.
Encapsulation may refer to:... , 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
Software maintenance
Software maintenance in software engineering is the modification of a software product after delivery to correct faults, to improve performance or other attributes, or to adapt the product to a modified environment .... . 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:
In computer science control flow refers to the order in which the individual statement , Instruction or function calls of an imperative programming or functional programming computer program are execution or evaluated.... statements, foreach
Foreach
For each is a computer language idiom for traversing items in a Collection class. Foreach is usually used in place of a standard for loop statement ....
In computer science control flow refers to the order in which the individual statement , Instruction or function calls of an imperative programming or functional programming computer program are execution or evaluated.... , elseif, else statements
variable modifiers - For example
functions - For example
output filters
possiblity to create own modifiers / functions / output filters
advanced caching of pages
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. One contains the presentation code, including Smarty variables:
In the business logic code you can configure Smarty to use this template:
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', '
A web template is a tool used to Separation of concerns content from presentation in web design, and for mass-production of web documents. It is a basic component of a web template system....
External links
by Cezar Floroiu - Smarty tutorial
- from DevPapers.com by Sergey Makogon
Smarty Cheat Sheet for Templates Designers and Programmers