Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Smarty (template engine)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Web template system}} {{About|a web template system|other uses|Smarty (disambiguation){{!}}Smarty|similarly named items|Smarties (disambiguation)}} {{Infobox software | name = Smarty | logo = Smarty-logo.png | developer = Monte Ohrt, Messju Mohr, Uwe Tews | programming language = [[PHP]] | genre = [[Template engine (web)|Template Engine]] | license = [[GNU Lesser General Public License|LGPL]] | website = {{URL|www.smarty.net}} | latest release version = {{wikidata|property|edit|reference|P348}} | latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}} | latest_preview_version = | latest_preview_date = }} '''Smarty''' is a [[web template system]] written in [[PHP]]. Smarty is primarily promoted as a tool for [[separation of concerns]].<ref name="Parr000">{{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 |isbn = 1-58113-844-X}}</ref> Smarty is intended to simplify [[Encapsulation (computer science)|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 [[Variable (programming)#Interpolation|substituted]] with other code. Tags are directives for Smarty that are enclosed by [[Delimiter#Bracket delimiters|template delimiters]]. These directives can be [[Variable (programming)|variables]], denoted by a dollar sign ($), functions, [[Conditional (programming)|logical]] or [[control flow|loop]] statements. Smarty allows PHP programmers to define custom functions that can be accessed using Smarty tags. == Smarty example == Since Smarty separates PHP from HTML, there are two files β one contains the presentation code: an HTML template, including Smarty variables and tags - <syntaxhighlight lang="smarty" inline>{$title_text|escape} {$body_html}</syntaxhighlight> - which might look like this: <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> <!-- this is a little comment that will be seen in the HTML source --> </html> </syntaxhighlight> The [[business logic]] to use the Smarty template above could be as follows: <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', '<p>BODY: This is the message set using assign()</p>'); $smarty->display('index.tpl'); </syntaxhighlight> ==Further reading== * {{cite book |title=Smarty PHP Template Programming And Applications |author1=Hasin Hayder |author2=J. P. Maia |author3=Lucian Gheorghe |isbn=978-1-904-81140-4 |year=2006}} == See also == {{Portal|Free and open-source software}} * [[Comparison of web template engines]] * [[Web template]] ==References== {{reflist}} ==External links== * {{Official website|http://www.smarty.net/}} [[Category:Free software programmed in PHP]] [[Category:Template engines]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:About
(
edit
)
Template:Cite book
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Main other
(
edit
)
Template:Official website
(
edit
)
Template:Portal
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Template other
(
edit
)