Smarty (template Engine)
Smarty
Smarty-logo.png
Developer(s)Monte Ohrt, Messju Mohr, Uwe Tews
Stable release
3.1.33 / 17 September 2018; 2 months ago (2018-09-17)[1][2]
Written inPHP
TypeTemplate Engine
LicenseLGPL
Websitewww.smarty.net

Smarty is a web template system written in PHP. Smarty is primarily promoted as a tool for separation of concerns.[3] Smarty 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.

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 - {$title_text|escape} {$body_html} - which might look like this:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4    <meta charset="utf-8">
 5    <title>{$title_text|escape}</title>
 6 </head>
 7 
 8 <body> {* This is a little comment that won't be visible in the HTML source *}
 9 {$body_html}
10 </body> <!-- this is a little comment that will be seen in the HTML source -->
11 </html>

The business logic to use the Smarty template above could be as follows:

 1 define('SMARTY_DIR', 'smarty-2.6.22/');
 2 require_once(SMARTY_DIR . 'Smarty.class.php');
 3 
 4 $smarty = new Smarty;
 5 $smarty->template_dir = './templates/';
 6 $smarty->compile_dir = './templates/compile/';
 7 
 8 $smarty->assign('title_text', 'TITLE: This is the Smarty basic example ...');
 9 $smarty->assign('body_html', '<p>BODY: This is the message set using assign</p>');
10 
11 $smarty->display('index.tpl');

Further reading

  • Hasin Hayder; J. P. Maia; Lucian Gheorghe (2006). Smarty PHP Template Programming And Applications. ISBN 978-1-904-81140-4.

Recommendations

See also

References

  1. ^ https://github.com/smarty-php/smarty/blob/v3.1.30/change_log.txt
  2. ^ https://www.smarty.net/
  3. ^ Parr, Terence John (2004). Enforcing strict model-view separation in template engines. Proceedings of the 13th international conference on World Wide Web. ISBN 1-58113-844-X.

External links


  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.

Smarty_(template_engine)
 



 

Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.


Manage research, learning and skills at defaultlogic.com. Create an account using LinkedIn to manage and organize your omni-channel knowledge. defaultlogic.com is like a shopping cart for information -- helping you to save, discuss and share.


  Contact Us