Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Largest classified with thousands of ads at Shoppok

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Find Wedding Dresses Online at Canada from Ca-dresses.com

Find your local domestic cleaner

Brautkleider auf Topwedding.de

Best Wedding Dresses Australia at AuBridalDresses.com

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Advertisement

Chapter 1. What is Smarty?

Smarty is a template engine for PHP. More specifically, it facilitates a manageable way to separate application logic and content from its presentation. This is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person.

For example, let's say you are creating a web page that is displaying a newspaper article.

  • The article $headline, $tagline, $author and $body are content elements, they contain no information about how they will be presented. They are passed into Smarty by the application.

  • Then the template designer edits the templates and uses a combination of HTML tags and template tags to format the presentation of these variables with elements such as tables, div's, background colors, font sizes, style sheets, svg etc.

  • One day the programmer needs to change the way the article content is retrieved, ie a change in application logic. This change does not affect the template designer, the content will still arrive in the template exactly the same.

  • Likewise, if the template designer wants to completely redesign the templates, this would require no change to the application logic.

  • Therefore, the programmer can make changes to the application logic without the need to restructure templates, and the template designer can make changes to templates without breaking application logic.

One design goal of Smarty is the separation of business logic and presentation logic.

  • This means templates can certainly contain logic under the condition that it is for presentation only. Things such as including other templates, alternating table row colors, upper-casing a variable, looping over an array of data and displaying it are examples of presentation logic.

  • This does not mean however that Smarty forces a separation of business and presentation logic. Smarty has no knowledge of which is which, so placing business logic in the template is your own doing.

  • Also, if you desire no logic in your templates you certainly can do so by boiling the content down to text and variables only.

Some of Smarty's features:

  • It is extremely fast.

  • It is efficient since the PHP parser does the dirty work.

  • No template parsing overhead, only compiles once.

  • It is smart about recompiling only the template files that have changed.

  • You can easily create your own custom functions and variable modifiers, so the template language is extremely extensible.

  • Configurable template {delimiter} tag syntax, so you can use {$foo}, {{$foo}}, <!--{$foo}-->, etc.

  • The {if}..{elseif}..{else}..{/if} constructs are passed to the PHP parser, so the {if...} expression syntax can be as simple or as complex an evaluation as you like.

  • Allows unlimited nesting of sections, if's etc.

  • It is possible to embed PHP code right in your template files, although this may not be needed (nor recommended) since the engine is so customizable.

  • Built-in caching support

  • Arbitrary template sources

  • Custom cache handling functions

  • Plugin architecture

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 13 plus 20? (Are you human?)

Advertisement

Sponsors [info]

UK Web Hosting @webhost.uk.net
Best Web Hosting @rshosting.com
Web Hosting UK @webhostinguk.com
Unlimited Web Hosting @infrenion.com
App Entwicklung @morphodo.com
First Click Internet Marketing @fcinternetmarketing.com
Credit Card Processing Company